Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rid Duplicates with SQL
Message
 
 
To
02/11/2014 17:34:41
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01610363
Message ID:
01610403
Views:
54
>Hi All:
>
>Consider the following table, FOO.
>
>
>Field1   Field2   Field3   Field4   Field5   Field6   Field7   Field8   Field9
>cat        dog       ...          ...          ...         ...          ...          ...          ...
>cat        mouse
>fish       goat
>cat        dog
>
>
>If I say SELECT FOO.*, I will get 4 records. However, I do not want duplicates of field1+field2. I do not care which record I get.
>
>SELE DISTINCT will not work, since there may be differences in the other fields.
>
>Thanks,
>
>Yossi

If you don't have PK field in your table (you should have it) and field3 is always different, then
select T.* from myTable T ;
INNER JOIN (select field1, field2, min(field3) as uniqueFld3 from myTable group by field1, field2) X ;
on T.field1 = X.field2 and T.field2 = X.field2 and T.field3 = X.field3
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform