Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting Duplicate Records
Message
From
08/01/2003 11:49:44
 
 
To
08/01/2003 11:46:08
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00739350
Message ID:
00739354
Views:
13
Opps, that question should read:
Is it possible to do what I want to do in one single SQL - Delete statement?

>Hi,
>
>I have a cursor that answers the question "Which organizations are in the categories that I select?" There is a 1 to many relationship b/w organizations and categories. Say the user wants to know what orgs are in the categories "Shoe Shop" and "Shoe Repair" The org, "Joe's Shoes" is in both categories so it would appear in the cursor twice. I only want "Joe's Shoes" to appear once. The cursor has a primary key, org_pk.
>
>I know that the following SQL statement will identify duplicate records:
>SELECT Org_PK FROM C_Cursor GROUP BY Org_PK HAVING COUNT(Org_PK) > 1
>
>So I tried this:
>DELETE FROM C_Cursor ;
> WHERE Org_PK IN ;
> (SELECT Org_PK FROM C_Cursor GROUP BY Org_PK HAVING COUNT(Org_PK) > 1)
>
>This will delete the duplicate records, but it will delete all of them. For example say C_Cursor intially has these values:
>
>C_Cursor
>6036
>6036
>6036
>1000
>2063
>2063
>
>After I run that DELETE FROM ... statement we get
>
>C_Cursor
>1000
>
>What I really want is:
>
>C_Cursor
>6036
>1000
>2063
>
>I actually got the results I wanted in a few steps:
>
>* get a cursor of duplicates
>SELECT Org_PK ;
> FROM C_Cursor ;
> GROUP BY Org_PK HAVING COUNT(Org_PK) > 1 ;
> INTO CURSOR C_Dups
>
>* delete the duplicates
>DELETE FROM C_Cursor WHERE Org_PK IN (SELECT Org_PK FROM C_Dups)
>
>* we need one record for the duplicates, so insert
>SELECT C_Dups
>GO TOP
>SCAN
> INSERT INTO C_Cursor (Org_PK) VALUES (C_Dups.Org_PK)
>ENDSCAN
>
>But that process seems long. Is it possible to do what I want to do in SQL - Delete statement? Or another better alternative?
>
>Thanks,
>Chris
Previous
Reply
Map
View

Click here to load this message in the networking platform