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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Query Design Question

Status
Not open for further replies.

MrTBC

Technical User
Nov 19, 2003
610
US
Access 2000.
Sorry I'm sure this is a really simple one but I'm stumped.
If you have two tables joined via a one-many relationship, how can you design a query to show only the records in the 'One' table which DO NOT have a corresponding entry in the 'Many' table.
e.g. Products that have NOT been ordered


Thanks very much.
 
Something like this ?
SELECT A.* FROM parentTable A LEFT JOIN childTable B ON A.PK = B.FK
WHERE B.FK Is Null;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
One solution:

SELECT * FROM PRODUCTS WHERE PRODUCTID NOT IN (SELECT DISTINCT PRODUCTID FROM ORDERS)

Leslie
 
Aaaaah - that easy. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top