#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Query, equal tag and more variable


    Hy,

    (Sorry English)

    Please help.

    I have a Mysql table:

    user_id | workinghours
    ----------------------
    1 | 3
    1 | 8
    2 | 4
    2 | 8
    3 | 13
    3 | 15
    5 | 3
    5 | 8
    5 | 10
    6 | 3
    6 | 10
    6 | 16
    6 | 20
    6 | 21

    I would like query in this table:
    SELECT user_id FROM tablename WHERE "workinghours = 3 AND workinghours = 8 AND ..."
    Then I get user_id = 1,5..... , but this query not working. ( In this case, only those people who are on workinghours (3,8) )

    Thanks a lot!

    David
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,026
    Rep Power
    4210
    Code:
    SELECT user_id 
      FROM tablename 
     WHERE workinghours IN (3,8)
    GROUP
        BY user_id
    HAVING COUNT(*) = 2
    r937.com | rudy.ca
    please visit Simply SQL and buy my book
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Thanks a lot!!!!!!!!!

    Originally Posted by r937
    Code:
    SELECT user_id 
      FROM tablename 
     WHERE workinghours IN (3,8)
    GROUP
        BY user_id
    HAVING COUNT(*) = 2

IMN logo majestic logo threadwatch logo seochat tools logo