Skip to content
Advertisement

SQL – Matching only the values in IN clause (not less or more)

I am having the following ManyToMany table TEAM_USERS with the below data:

So, I want to get the TEAM_ID that is having only two user with the USER_ID IN (3, 4), in this case it’s team 11. But I am getting team 1, 11, and 12. And I want only team 11.

I did the following code but I am not getting the expected results

the results for this query is:

So, please any help would be really appreciated.

=============== EDIT: The list is unique, and there is no duplicates

Advertisement

Answer

Move the WHERE-condition into conditional aggregation.

As long as the combination team_id/user_profile_id is unique:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement