I have the following query:
SELECT
[Id], [Number] AS [Purchase Order], [OldProduct] AS [Old Product],
(SELECT [Id]
FROM
(SELECT [Id], [Name]
FROM [Products]
UNION ALL
SELECT [ProductId] AS [Id], [Alias] AS [Name]
FROM [ProductAliases]) AS [ProductNames]
WHERE [ProductNames].[Name] = po.[OldProduct]) AS [ProductId]
FROM
[PurchaseOrders] po
How could I limit the results to only those rows where [ProductId]
is NULL?
If I just add a WHERE
clause at the end, that doesn't work. There is no error but the PurchaseOrders
table has a ProductId
column so it just references that. Also, I believe the SELECT
clause runs at the end so I don't think that makes sense to filter it before the SELECT
clause.