Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to SELECT all fields with one field being DISTINCT?
Message
De
19/11/2001 09:44:09
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00583382
Message ID:
00583402
Vues:
20
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform