Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select with Subquery confusion
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00053103
Message ID:
00053188
Views:
24
The EXIST key word is like a NOT EMPTY (or testing _TALLY, but you can't do that in a SELECT-SQL). Ie: if the inner query is not empty, the record is included in the main query result. If the inner query is empty, the record is not included in the main query result (obvious, isn't it?:)).

In your case, the inner query doesn't depend on the main one, so, the result is the same for all records in the source table. Since this result of the inner query is not empty and you test with !EXIST, the condition is false for all records, so the main result is empty.

This also explains the other sample you gave in this thread.

Vlad

>OK, using subqueries is something I'm little new at, and I cant figure out the following:
>
>SELECT handles.account,handles.handle,handles.progtype, ;
> handles.stype,styperef.ptype, HANDLES.REF_NUM ;
> from handles,styperef ;
> WHERE STYPEREF.STYPE==HANDLES.STYPE AND ;
> styperef.ref_num=handles.ref_num AND ;
> STYPEREF.PTYPE="A" AND PROGTYPE<>"A" ;
> AND NOT INLIST(SUBSTR(handle,1,2),"SP","DD","PN","P4") ;
> AND NOT INLIST(SUBSTR(handle,1,3),"TRD") ;
> AND NOT INLIST(handles.stype,"LR") ;
> INTO CURSOR alpha_x &&Returns 7809 records and is correct
>
>SELECT * FROM ALPHA_X WHERE NOT EXISTS( ;
> SELECT * FROM ALPHA_X WHERE stype="WL " AND progtype="NP") ;
> INTO CURSOR ALPHATMP &&Returns Empty Result
>
>If I run the subquery alone I get 5155 records with stype="WL " AND progtype="NP" Therefore my ALPHATMP cursor should have 2654 records, not zero. What did I do wrong this time? Note - this code currently running in FPW 2.6, couldnt test under 5.0a until next week because Monthend processing is running.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform