Here is my query:
SELECT publicationId AS PublicationID
FROM dbo.PublicationOwner
WHERE ownerId = 31331
UNION
SELECT AreaBuy.AreaBuyID AS PublicationID
FROM AreaBuy
JOIN PublicationAreaBuy ON AreaBuy.AreaBuyID = PublicationAreaBuy.AreaBuyID
WHERE PublicationAreaBuy.PublicationID IN (SELECT publicationId
FROM dbo.PublicationOwner
WHERE ownerId = 31331)
ORDER BY publicationId
What I am trying to do is:
Get the list of publication ID's where the owner id is equal to 31331 and add in (union) any areabuy ids (as publication id) if the publication id in the area buy table are in the results from the first query.
What is wrong? And yes, 31331 is the correct owner id and does return a publication ID which is also in the area buy table.