INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL Syntax

report/remove duplicate records by danceman
Posted: 25 Jan 07

To remove duplicate records from a table.  What field(s) determine a duplicate, such as

SSN, or  SSN and code assignment.  In my example shown I use SSN and a code that desinates a group assigned to.  The SSN can have more then one unique code assignment.

First verify duplicates with below command

select ssn,p_code count(*) from p_code group by ssn,p_code having count(*) >1
The COUNT function produces a total of all records, but adding the GROUP BY there is a individual line for each unquie SSN+Code.  Adding the having clause > 1 shows only the duplicates.


Next make a file of all records without the dupiclates with this command

select * , count(distinct ssn+p_code) from p_code group by ssn,p_code into table temp
DISTINCT produces only one for each duplicate record and for each non-duplicate.  The temp table produced will have all fields plus a field added that shows the count.

Now zap the p_code table, then append from the file temp

The extra field in the temp gets drouped when you append.

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close