Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is MAX() a good choice where GROUP BY?
Message
 
 
À
14/09/2020 13:35:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01676115
Message ID:
01676128
Vues:
38
>>>>This is 1-M Relationship.
>>>>
>>>>Table2 - Parent Table. Field1 is PK field. One record for each Field1 PK
>>>>Table1 - Foreign table. Field1 is a Foreign key. It could have several records for the same value of Field1.
>>>>
>>>
>>>:) Usually I would think in reverse that's why it was a bit confusing.
>>>
>>>Now, back to the original question - which rows of Table1 do you want to get per single Field1 (PK) in the table2 ?
>>
>>Here is an example:
>>
>>*-- Table1
>>*-- Strucutre:
>>FIELD1     FIELDX    FIELDY
>>2
>>4
>>2
>>2
>>1
>>4
>>4
>>
>>*-- Table 2
>>*-- Structure
>>FIELD1     FIELD2    FIELD3
>>1               'ABC'      '123'
>>2               'XYZ'      '456'
>>3              'DFD'      '333'
>>4              'DDF'      '444'
>>
>>*-- Resulting query should be
>>FIELD1     FIELD2     FIELD3
>>1               'ABC'      '123'
>>2               'XYZ'      '456'
>>4              'DDF'      '444'
>>
>>
>>Now that I wrote the example, above, I think I can SELECT from Table2 and JOIN Table1 on FIELD1.
>>
>>But the question is, if I follow my initial example and SELECT FROM Table1 and JOINT Table2, is it better to use
>>DISTINCT() or GROUP BY (with MAX())?
>
>I think you'd have to test to see which of those is faster.
>
>Tamar

The speed is not that important (the tables are fairly small). What matter to me is accuracy. If I go with GROUP BY, I have to use MAX(). If I go with DISTINCT() I don't have to use MAX().
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform