Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
JOIN vs WHERE
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01406428
Message ID:
01406475
Views:
60
>Hi Rich,
>
>It's not clear what you want so I'll take a guess
>
>SELECT  cust.customer, COUNT(*) ;
>	FROM crsAllCust cust;
>		JOIN crsFillRate fr ON cust.customer = fr.custshipm ;
>	WHERE EXISTS ( SELECT 1 FROM crsFillRate fr WHERE cust.customer = custshipm AND EMPTY(PartOrders)) ;
>	GROUP BY cust.customer
>
>
Hi Sergey,

This query would not return customers that don't have corresponding records in the crsFillRate. You can modify it to be
SELECT  cust.customer, COUNT(*) ;
	FROM crsAllCust cust;
	LEFT	JOIN crsFillRate fr ON cust.customer = fr.custshipm ;
	WHERE fr.custshipm  IS NULL OR EXISTS ( SELECT 1 FROM crsFillRate fr WHERE cust.customer = custshipm AND EMPTY(PartOrders)) ;
	GROUP BY cust.customer
to match the original query. But when why do we need EXISTS ?
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform