Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP 5.0 & 6.0 - Nested SELECT's
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00188396
Message ID:
00188928
Views:
23
>>>>Thank you Rich, your sample solved the problem.
>>>>
>>>>>>These two lines run fine if I run one after the other.
>>>>>>
>>>>>>SELECT * FROM V1 WHERE MAXORDAMT > 50000
>>>>>>
>>>>>>SELECT * FROM CUSTOMER WHERE ALLT(COUNTRY) = 'USA'
>>>>>>
>>>>>>If I try to nest them, they don't run, what am I doing wrong?
>>>>>>SELECT * FROM CUSTOMER ;
>>>>>> WHERE MAXORDAMT > 50000 AND ;
>>>>>> (SELECT * FROM CUSTOMER WHERE ALLT(COUNTRY) = 'USA')
>>>>>
>>>>>If this posting has the correct table names in the first two SELECT commands, here's the syntax for the subquery:
SELECT * FROM CUSTOMER ;
>>>>>	WHERE ALLT(COUNTRY) = 'USA' ;
>>>>>	AND CustKey IN (SELECT CustKey FROM V1 WHERE MAXORDAMT > 50000)
>>>>>HTH,
>>>>>Rich.
>>>
>>>I take it V1 is the orders table detail with an associated customer number. I suppose the query runs, but you're bringing up a larger set than you need to. Just run the custkey subquery by itself and you'll notice. The subquery should have the DISTINCT clause in it.
>>
>>Really? I thought the DISTINCT clause in the subquery would just add overhead, rather than actually speeding up the main query.
>
>Would you care to elaborate? Maybe I've been doing it wrong this whole time. The reference I have does not say anything about added overhead. My gut feeling tells me that getting a smaller result set in the subquery is better.

I was thinking that adding the DISTINCT clause to the subquery would make it spend more time eliminating duplicates, and might not actually speed up the main query. But I don't know. My various tables aren't that big anyway, so the tests I just did went by too fast to compare.
Previous
Reply
Map
View

Click here to load this message in the networking platform