Firstly I would like to say that I am sorry if it is a duplicate, I really did not find anything that would help me. I am quite new to real SQL development, so if somebody could even point me to some resources I would very much appreciate it.
Problem:
I am not sure how to handle things, I suspect the need of UNION and LEFT OUTER JOIN.
Summary:
Table1: user1 history of viewed articles (1 column with article IDs)
Table2: user2 history of viewed articles (1 column with article IDs)
Table3: articles (more columns has IDs)
Now I would like an UNION between user1 and user2 history and get the IDs of articles that both have not seen yet limited to 10.
Pseudo code:
(SELECT * FROM user1 UNION SELECT * FROM user2) as UnionTable SELECT top(10) * FROM article WHERE UnionTable.id <> article.id OR SELECT * FROM articles LEFT OUTER JOIN UnionTable The expected outcome is a list of article IDs that are not found in the union table. Are there any other better ways? Subqueries or procedures?