Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning sets of records from a table with limited crit
Message
De
12/01/2004 17:14:50
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
 
À
12/01/2004 17:10:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00866172
Message ID:
00866177
Vues:
18
>>I want to return a set of records where the ID is the same, but I don't know the value of the ID before the SQL runs. For example, from the following data I want C, D, E and F returned in the results because they all share the same ID (33333) as the D record:
>>
>>
>>Name  ID
>>
>>A     11111
>>B     22222
>>C     33333
>>D     33333
>>E     33333
>>F     33333
>>G     44444
>>
>>
>>
>>SELECT Name, ID FROM MyTable WHERE Name == 'D'
>>
>>
>>This obviously only returns the one D record, but I want the other 3 also. Any way to do it without doing multiple SQLs and a SCAN? Can the TOP clause be used somehow?
>
>I'm not sure TOP would help, but EXISTS would, e.g. (and a variable can be used in place of the 'D')
>
>select Name, ID ;
>  from MyTable m1 ;
>  where exists ;
>    (select *  ;
>      from MyTable ;
>      where Name == 'D' ;
>      and ID=m1.ID) ;
>into cursor cuCommonIDs
>
I don't know what the ID is before the SQL runs. Not sure what you're doing with the ID=m1.ID in the 2nd SQL. If I remove that I think it may work, though I'm curious what you were trying to do.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform