Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select distinct not the answer
Message
 
 
To
16/05/2012 11:21:03
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Miscellaneous
Thread ID:
01543687
Message ID:
01543689
Views:
93
This message has been marked as the solution to the initial question of the thread.
>Hi All:
>
>I have a table where there are dupes in a particular column, FOO. I want to create a cursor that will contain only one record per FOO, so I coded:
>
>
>SELECT * ;
>FROM ImpHeader ;
>ORDER BY FOO ;
>GROUP BY FOO ;
>INTO CURSOR curHeader READWRITE
>
>
>VFP doesn't like the GROUP BY, but it is a pain to GROUP BY all the other fields or aggregate them. I do need the data from the other fields, so SELECT DISTINCT FOO would not help.
>
>What is the solution?
>
>Thanks,
>
>Yossi
select * from ImpHeader I1 where PK IN (select Min(PK) from ImpHeader i2 GROUP BY Foo WHERE i2.Foo = I1.Foo)
Actually, you don't even need to make this query to be correlated, and this version will also work as long as you have a primary key:
select * from ImpHeader I1 where PK IN (select Min(PK) from ImpHeader i2 GROUP BY Foo)
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