Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding LEFT JOIN
Message
From
23/08/2005 11:16:04
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01042886
Message ID:
01042956
Views:
39
>>>These two queries are supposed to be the same. Can you explain the difference between these two? It looks like yours works every time, while the original with IsNull sometimes fails to work. I can not understand it.
>>
>>Classic error: and ( logical multiplier ) priority!
>>
>>WHERE  Billing_charges.cbilling_main_fk = ( ?vp_cBilling_main_fk )
>>AND Viscodes.ccategory_description LIKE ( "REVENUE_CODES%" )
>>OR Viscodes.ccategory_description IS NULL
>>* IS
>>WHERE ( Billing_charges.cbilling_main_fk = ( ?vp_cBilling_main_fk )
>>AND Viscodes.ccategory_description LIKE ( "REVENUE_CODES%" ) )
>>OR Viscodes.ccategory_description IS NULL
>>* CORRECT is
>>WHERE Billing_charges.cbilling_main_fk = ( ?vp_cBilling_main_fk )
>>AND (Viscodes.ccategory_description LIKE ( "REVENUE_CODES%" )
>>OR Viscodes.ccategory_description IS NULL)
>>
>>
>>But even if it works, this last form is not equivalent to mine;
>>the meaning in relational algebra sense it is different!
>
>Well, of course I used the last syntax, e.g. I'm not THAT dump < g >. But I still fail to see the difference, though yours avoid using NULL and therefore more elegant.


I apologize a lot!
But you should be more precise when you say that it doesn't work
When it doesn't work, that results you get ?

Elegant is a side effect.

Can Viscodes.ccategory_description to be NULL ?

A example where the two syntaxes are different:
CREATE CURSOR T1 (AA I,BB I NULL)
INSERT INTO T1 VALUES (1,4)
INSERT INTO T1 VALUES (2,NULL)
INSERT INTO T1 VALUES (2,NULL)

SELECT * FROM T1 LEFT JOIN T1 T2 ON T2.AA=T1.AA;
WHERE T2.BB=4 OR T2.BB IS NULL

SELECT * FROM T1 LEFT JOIN T1 T2 ON T2.AA=T1.AA;
AND T2.BB=4
Except special cases,
it never needs to use WHERE outertable.field IS NULL
in a Left join on a outerfield that is not key primary
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform