If you have mySql 4 use a sub-query select user_id from user_profile where user_id not in (select user_id from team_member where team_id = 2)
Hi, I got a difficult problem with a SELECT query: In my application there are two tables, one for all users (user_profile) one for a user-in-team relation. I want to know, which user is still not in a speciffic team. Users can be in more than one team, but we don't care about that. Example: user_profile: +---------+ | user_id | +---------+ | 1000 | | 1001 | | 1002 | | 1003 | | 1004 | | 1005 | | 1006 | | ... | +---------+ team_member: +---------+---------+ | team_id | user_id | +---------+---------+ | 1 | 1000 | | 1 | 1004 | | 1 | 1005 | | 2 | 1006 | | 2 | 1003 | | 2 | 1000 | | 2 | 1001 | | 2 | 1005 | | 3 | 1001 | | 3 | 1005 | | 3 | 1002 | | 3 | 1003 | | ... | ... | +---------+---------+ Who is not in team no. 2? Result: +---------+ | 1002 | | 1004 | +---------+ --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php