MySQL Forums
Forum List  »  Newbie

Re: Show missing records
Posted by: Ramalingam Chelliah
Date: August 24, 2004 01:21AM

Hi,
Use Left Outer Join for getting results as how you expect them to be...

Tables are joined based on Join Condition ...
If you join tables with condition
ON (backorders.lineID <> items.ITEM_ID)
Then they will be paired with this condition

Say T1 T2 are tables

T1

F1 F2
1 Hai
2 Try
3 Why
4 Sky

T2 is subset(subtable) of T1

( mysql> CREATE TABLE T2 AS
SELECT * FROM T1 WHERE T1.ID<3 ;)

T2

F1 F2
1 Hai
2 Try


Now as per given condition
T1(1 ,3,4) will be paired with T2(2) --only 2 is exempted
T1(2,3,4) will be paired with T2(1) --only 1 is exempted



Now the right solution

mysql> SELECT items.QUANTB,items.ITEM_ID,backorders.lineID
FROM
items
LEFT OUTER JOIN backorders
ON items.ITEM_ID = backorders.lineID
WHERE backorders.ID IS NULL
AND items.QUANTB > 0
group by
items.ITEM_ID ;

Hope this helps you....

Regards,
Ram.








We Learn the Most When we have to Invent

Options: ReplyQuote


Subject
Written By
Posted
August 23, 2004 11:43AM
Re: Show missing records
August 24, 2004 01:21AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.