How can I add data based on a join?

RSW

Registered User.
Local time
Today, 09:38
Joined
May 9, 2006
Messages
178
I have a table of orders for particular products, and a table of products that are on sale. (It's not ideal database structure, but that's out of my control.) What I want to do is outer join the order table to the sale table via product number, but I don't want to include any particular data from the sale table, I just want a Y if the join exists or N if it doesn't in the output. Can anyone explain how I can do this (ideally in Access SQL)

Thanks in advance!
 
This creates a list of all Order numbers that are present in the Orders table (tblOrders), and uses a left outer join and a calculated field named 'Present' to indicate whether each Order has a ProductNumber that matches a ProductNumber in the sales table (tblSales).


Code:
SELECT tblOrders.OrderNumber, IIf(IsNull([tblSales]![ProductNumber]),"N","Y") AS Present
FROM tblOrders LEFT JOIN tblSales ON tblOrders.ProductNumber = tblSales.ProductNumber 
GROUP BY tblOrders.OrderNumber, IIf(IsNull([tblSales]![ProductNumber]),"N","Y");

Not entirely sure if that's what you were after but that's what I got from your description.
 
  • Like
Reactions: RSW
I will try that out. Thanks for your quick response!
 

Users who are viewing this thread

Back
Top Bottom