Select users that are in the same team
-- get all the unique team ids which have both user1 and user2
SELECT DISTINCT a.teamid 
FROM
( SELECT teamid FROM `TEAMUSER` WHERE userid = user1 ) AS a
INNER JOIN 
( SELECT teamid FROM `TEAMUSER` WHERE userid = user1 ) AS b 
ON a.team_id = b.team_id