RDBMS SQL Server, T-SQL
Consider a table that links information from two different tables: Articles and Categories. This table contains for each Article one or several entries containing the ID of the Categories the Article belongs to. Therefore, a
SELECT * FROM TABLE WHERE ARTICLEID = X
returns 1 to n results.
I am looking to build a query which allows me to compare Articles that have the exact same combination of Categories. I’ve been trying with INTERSECT, but that does not return any rows. An example:
ARTICLEID CATEGORYID
1 1
1 2
1 4
2 1
2 4
3 1
3 2
3 4
4 2
4 4
5 1
5 2
5 4
The query for ARTICLEID = 1 should return 3 and 5, for ARTICLEID = 3 should return 1 and 5, et cetera.
EDITed: This should work
Just run this exact query, changing only the XXX to whatever articleID that you need to match. It should work.