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:
00053403
Views:
26
>Roxanne,
>
>I always had best luck in subqueries when REPEATING a file already used by always giving the repeat instance of the file an alias and referring to all fields in the subquery using the alias. Less chance to confuse the ol SQL syntax checker.
>
>Good luck,
>Jim N
>
Jim,
You were right, using an alias and referencing all the fields in the subquery was the trick here. I first tried just adding the field references to my subquery and that wasnt quite enough, still got the empty result. But the following worked fine:

SELECT * FROM ALPHA_X A WHERE NOT EXISTS( ;
SELECT * FROM ALPHA_X B WHERE ;
a.handle=b.handle AND a.ref_num=b.ref_num ;
AND b.stype<>"WL " AND b.progtype<>"NP") ;
INTO CURSOR ALPHATMP

Unfortunately, the tables being used here are like most in my Data Warehouse system - Non-normalized, thus the double field identifier. So this did work, but the example given below by Edward is much faster and is the way I'll move this code into production. Lesson learned here (I think) - Don't use Subqueries for single table processing.

>>>Why not to use:
>>>SELECT * FROM ALPHA_X WHERE stype!="WL " OR progtype!="NP" ;
>>> INTO CURSOR ALPHATMP
>>
>>I did do it that way just to get job out, but this week's learning curve was to conquer Subqueries... Was just trying to meet the daily workload AND learn something at the same time. :D)

Thanks to Jim and everybody, I would of just blown this off and not fully understood "When & Where" subqueries are appropriate without your input! :D)
Roxanne M. Seibert
Independent Consultant, VFP MCP

Code Monkey Like Fritos
Previous
Reply
Map
View

Click here to load this message in the networking platform