We have these 3 tables:
USERS
userid
name
email
TEAMS
teamid
name
options (0,1,2 or 3)
TEAMUSER
id
teamid
userid
isadmin (0 or 1, if they are administrator of team)
Let's say we have user 1, 2 and 3 inside users table. Lets also say we have 3 teams, team 1, 2 and 3.
User 1 and 2 are part of the same team, the team id 3. So there are rows in teamuser table also.
User 1 is also part of team 2, and user 3 is part of team 3, but it's not relevant here.
THE QUESTION IS THIS:
How do I get an SQL that says:
SHOW ME THE TEAMS WHERE USER 1 AND 2 (OR X AND Y) ARE PART OF THE SAME TEAM? (and isadmin to see if they are admin and the team options also)
So user 1 and 2 can be part of more than 1 team together, they can be together in several teams, and that's what I'm interested in. Not the teams that they are individually in, but only the teams that they are both in.
So it would be awesome to get a list of rows like this if it's possible in one query:
teamid | userid | isadmin | options
-----------------------------------
3 | 1 | 1 | 1
3 | 2 | 0 | 1
Best Answer