www.webdeveloper.com
Results 1 to 5 of 5

Thread: WHERE question

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    63

    WHERE question

    I have table which have column "username" and I want to select multiple values after WHERE, but I can`t find anywhere in google the right synthax. I want to do something like:


    SELECT * FROM messages WHERE username = 'aaa' , "john", "mike"

  2. #2
    Join Date
    Jul 2009
    Posts
    72
    u can do:

    SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

    or u can do

    SELECT * FROM messages WHERE username = 'aaa' OR username = "john" OR username = "mike"

  3. #3
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by Reis View Post
    u can do:

    SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

    or u can do

    SELECT * FROM messages WHERE username = 'aaa' OR username = "john" OR username = "mike"
    Oooo, I tried that but it didn`t work, that`s why I`m posting the thread

    "MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec )"

  4. #4
    Join Date
    Jun 2008
    Posts
    62
    The most common approach would be:
    Code:
    SELECT * FROM messages WHERE username IN ('aaa','john','mike');
    but this should work too:
    Code:
    SELECT * FROM messages WHERE username = 'aaa' OR username = 'john' OR username = 'mike';
    That will certainly return an empty set:
    Code:
    SELECT * FROM messages WHERE username = 'aaa' AND username = "john" AND username = "mike"

  5. #5
    Join Date
    Jun 2009
    Posts
    63
    Thanks, that did work

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles