Need a Programmers to Write MySQL JOIN Statement

Discussion in 'Programming' started by phpdoctor22, Jun 2, 2012.

  1. #1
    Simple job, all I need is a mysql JOIN query written.

    I need to select all users who do not belong to a specific team.

    Database Tables
    users: id, username
    users_teams: id, team_id, user_id

    EX. If there are 3 users, User1, User2, User3

    If user1 and user2 are assigned to team_id 1, I need for the query to only select User3. Keep in mind that users can belong to multiple teams.

    If you're interested PM me your skype, aim, or gtalk details.
     
    phpdoctor22, Jun 2, 2012 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    try this

    
    select u.id, u.username from users u
    left join users_teams t on (t.user_id=u.id)
    where t.user_id is not null
    Code (markup):
    or

    
    select u.id, u.username from users u
    where u.id not in (select distinct user_id from users_teams)
    
    Code (markup):
     
    gapz101, Jun 3, 2012 IP
  3. abbygaile

    abbygaile Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    hi...skype on my profile...add me up
     
    abbygaile, Jun 3, 2012 IP
  4. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    The second worked (first one is what I originally coded myself but wasn't functioning properly)
     
    phpdoctor22, Jun 3, 2012 IP