Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to SELECT all fields with one field being DISTINCT?
Message
From
19/11/2001 09:44:09
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00583382
Message ID:
00583402
Views:
18
Chris,
You could use the following:
SELECT * FROM MyTable GROUP BY myPrimaryKey INTO CURSOR myCursor
I'm not sure what you're trying to accomplish. In your sample you want distinct values of PrimaryKey. Shouldn't the table only contain unique values in the first place?

If not, beware that this kind of query won't work in most other SQL dialects like SQL Server and MS Access without specifying all the fields in the GROUP BY clause. This makes kind of sense since above query will arbitrary select the fields on which you don't GROUP BY.
Example:

MyPrimaryKey OtherField
------------ -----------------
01 Some value
01 Some other value
01 Yet another value
02 adsfas
02 yxcfasdf
etc

With above query, you will get only one record per MyPrimaryKey. However you don't know whether the OtherField will return "Some value", "Some other value" or "Yet another value". Do you see what I mean?

HTH
>Hi - is there a way to select all the fields in a table with an SQL SELECT command checking one field as DISTINCT... a bit like this but this doesn't work...
>
>SELECT * DISTINCT myPrimaryKey FROM myTable INTO CURSOR myCursor
>
>Any ideas?
>
>Thanks
Daniel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform