Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find non-matching rows?

Status
Not open for further replies.

milton747

Programmer
Apr 21, 2005
133
US
I'm trying to detect missing links in my tables.
The SQL below revealed 16 rows (2 orders) in the ITEMS table, which do *not* have a matching entry in the ORDERS table.


SELECT orders.orderID, items.orderID, items.itemcode, items.quantity, items.pricequote
FROM orders RIGHT JOIN items
ON orders.orderID = items.orderID;


eg:
ITEMS ORDERS
OID OID
123 123
123
123
123
126 No entry
126
127 127

I would like the SQL to show ONLY the rows that exist in the ITEMS table that do *not* have a matching order table entry. In this case:
126
126

Any assistance welcome.

Thanks.
 
Code:
SELECT items.orderID, items.itemcode, items.quantity, items.pricequote
FROM items LEFT JOIN orders
ON orders.orderID = items.orderID
WHERE orders.orderid IS NULL

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top