Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning sets of records from a table with limited crit
Message
From
12/01/2004 17:14:50
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
12/01/2004 17:10:14
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00866172
Message ID:
00866177
Views:
21
>>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform