Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Question
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00478259
Message ID:
00478495
Vues:
25
>Gavin,
>
>That would produce a single column table with distinct
>field values.
>
>I want all fields from the table, but in only want records
>which are not duplicate. I can key on the BillCode field.
>
>
>Thanks

The problem you get using GROUP BY and DISTINCT clauses is what data is going to be returned. If you use DISTINCT, then all fields are checked to make sure they are not duplicates. If the BillCode is duplicated but there are other data fields that aren't, you will get all records because VFP doesn't consider them to be duplicates.

Using GROUP BY doesn't help much in this case either because if you group by BillCode, you will get only occurrence of BillCode but the other fields will depend on the physical location within the table. You will get the data associated with the record that that has the highest record number.

Ex.
rec#   BillCode      Data1
1        0001         29
2        0001         32
3        0002         30
select * from mytable group by billcode

Results
BillCode          Data1
  0001              32
  0002              30
IMO, you should use a subquery to retrieve the PKs and use that to get the data from the main table. (can be either character or numeric based PK values)
select * from mytable where mytable.PK in ;
   (select min(mytable1.PK) from mytable alias mytable1 group by mytable1.billcode)
HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform