SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Atlanta
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL INNER JOIN Problem

    I need this to return 1 result that matches 1111 that is in one of the usergroupid of 6, 9, 12, OR 13.
    This returns all matches for the selected usergroupid's?
    Or should I be using a different JOIN method?

    Code:
    SELECT 
      userfield.userid,
      userfield.field5,
      user.userid,
      user.usergroupid
    FROM
      userfield
      INNER JOIN user ON (userfield.userid = user.userid)
    WHERE
      userfield.field5 = '1111' AND 
      user.usergroupid = '6' OR 
      user.usergroupid = '9' OR 
      user.usergroupid = '12' OR 
      user.usergroupid = '13' 
    LIMIT 1

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    WHERE
      userfield.field5 = '1111' AND 
      ( user.usergroupid = '6' OR 
      user.usergroupid = '9' OR 
      user.usergroupid = '12' OR 
      user.usergroupid = '13' )
    see the parentheses? they ensure that the 1111 goes together with all of those OR conditions, and not just the first one only

    alternatively...
    Code:
    WHERE
      userfield.field5 = '1111' AND 
      user.usergroupid IN ( '6','9','12','13' )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Atlanta
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohh yes, Perfect,

    Thank you r937


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •