How do I union or join or CTE two selects, so that I only get the results that exists in both
SELECT DISTINCT userid FROM ads WHERE status <> 'BASIC'
Let’s say the result set is: 1, 2, 3, 4, 5
SELECT DISTINCT userid FROM ads WHERE state = 'Alabama'
Let’s say the result set is 2, 4, 5, 8, 9
Then I want 2, 4 and 5
This is what
INTERSECTdoes.I removed
DISTINCTfrom the queries as this is implied byINTERSECTin SQL Server (it does not implementINTERSECT ALL)