SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL multiple AND syntax

    Does anyone know if there is a similar syntax like IN() but for AND SQL logic?

    So for example

    table1 = (user_id,value).

    instead of saying:

    SELECT * FROM table1 WHERE value=1 AND value=20 AND value=5000.

    You could write:

    SELECT * FROM table1 WHERE value INNNN(1,20,5000)

    any ideas?
    I can't believe I ate the whole thing

  2. #2
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A value cannot equal two different things though.
    Adrian Schneider - Web Developer

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT user_id 
      FROM table1 
     WHERE value IN (1,20,5000)
    GROUP
        BY user_id
    HAVING COUNT(*) = 3
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •