>>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.