Apologies in advance if this has been asked before, but most of the similar examples I've seen only involve 2 tables and I'm having difficulty adapting my situation.
I have a query to select the Product Number and Unit Of Measure from table ProductList that are not in another table, PriceFile:
SELECT DISTINCT Prod_Num, [PriceFile].UM FROM [dbo].[PriceFile]
LEFT JOIN [dbo].[ProductList]
ON [PriceFile].Prod_Num = [ProductList].Product
WHERE [ProductList].Product IS NULL
With the data currently in the tables, this provides me with this:
Prod_Num UM
13717 HC
I now need to use the results of this query to query a third table, Products, which I attempt to do like this:
SELECT DISTINCT ProductID AS proCode,Prod_Desc AS proName,
UPC_Code AS proBarCode,UM_SOLDBY AS untCode
FROM [dbo].[Products]
WHERE ProductID IN
(
SELECT DISTINCT Prod_Num, [PriceFile].UM FROM [dbo].[PriceFile]
LEFT JOIN [dbo].[ProductList]
ON [PriceFile].Prod_Num = [ProductList].Product
WHERE [ProductList].Product IS NULL
)
But of course this gives me the error:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
And I'm not sure where to go from here. If I alter the subquery so that it only has Prod_Num, I get the Product Number I'm looking for, but I get both of the Units Of Measure for it that exist in the Products table.
proCode untCode
13717 DZ
13717 HC
And I only want the line with HC as the UM.
Like I said, I've tried multiple ways of JOIN-ing or WHERE EXIST-ing, but the 3rd table aspect is throwing me off.
Any help would be much appreciated.