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

Comparing a Table with a Query

Status
Not open for further replies.

XP2000

Programmer
Dec 14, 2001
40
GB
'TblMonth' has 2 fields: OrderRef, ProductNo
'QryOrders' has 2 fields: OrderRef, ProductNo

I need to determine the records that DO exist in 'TblMonth ' but that DO NOT exist in 'QryOrders'.
i.e.
Find the records where TblMonth.OrderRef matches QryOrders.OrderRef BUT subsequently there is no match between TblMonth.ProductNo and QryOrders.ProductNo


I just can't seem to get my head round this one.
Thanks.
 
A starting point:
SELECT M.*
FROM TblMonth M LEFT JOIN QryOrders O ON M.OrderRef=O.OrderRef AND M.ProductNo=O.ProductNo
WHERE O.ProductNo IsNull AND M.OrderRef In (SELECT DISTINCT OrderRef FROM QryOrders);

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top