Give the table below:
TABLE : USER_ASSETS
USER_ID | ASSET_ID
-------------------
1 | 1
-------------------
1 | 2
-------------------
1 | 3
-------------------
2 | 2
-------------------
2 | 3
-------------------
If I search for the USER_ID with ASSET_ID equals to 1 and 2, it should return USER_ID 1 as USER_ID 1 has ASSET_ID's 1 and 2.
If I pass ASSET_ID = 1 and 2 and 4, it should return 0 rows as there are no USER_ID's that have ASSET_ID 1, 2 and 4.
If I pass ASSET_ID 2 and 3 it should return USER_ID 1 and 2 as both of these USER_ID's has ASSET_ID 2 and 3.
I'm stuck right now as i couldn't find the correct query for my desired result.
I have tried this:
SELECT DISTINCT ID FROM USER_ASSETS WHERE ASSET_ID IN (1, 2);
But the result is wrong as it returns both USER_ID 1 and 2.
I have also tried:
SELECT DISTINCT ID FROM USER_ASSETS WHERE ASSET_ID = 1 AND ASSET_ID = 2
But this always return to 0 rows as the WHERE clause is executed to a single row at a time.