www.webdeveloper.com
Results 1 to 7 of 7

Thread: Selecting Rows with two `where` statements

  1. #1
    Join Date
    Jan 2003
    Location
    VA
    Posts
    419

    Selecting Rows with two `where` statements

    Hello, I am wondering if it is possible to select rows where, the where statement includes two of the same operator or something.. Im no good at explaning but this would be the best way to show you what I mean:

    SELECT DISTINCT `USER_ID2` WHERE `USER_ID` = '1' AND `USER_ID` = '4';

    and that would show all the fields where the user_id = 1 and 4... :-\

    thanks in advanced.

  2. #2
    Join Date
    May 2006
    Location
    the netherlands
    Posts
    454
    and that would show all the fields where the user_id = 1 and 4... :-\
    That's impossible. If the user_id = 1 it cannot be 4 (because it's 1)

    i guess you mean

    SELECT DISTINCT `USER_ID2` WHERE `USER_ID` = '1' OR `USER_ID` = '4';

  3. #3
    Join Date
    Jan 2003
    Location
    VA
    Posts
    419
    well, I want it to seelct them both, and display both of them,

  4. #4
    Join Date
    Jun 2006
    Posts
    472
    As long and USER_ID2 is a column name, it should work

    SELECT DISTINCT(USER_ID2), columnname,columname FROM tablename
    WHERE USER_ID` = '1' AND USER_ID = '4';
    Last edited by aussie girl; 07-03-2006 at 10:07 PM.

  5. #5
    Join Date
    Jan 2003
    Location
    VA
    Posts
    419
    it doesn't return any rows.. the actual code is:

    SELECT * FROM `friends` WHERE `user_id` = '1' AND `user_id` = '4'

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    user_id will never be equal to 4 when it is equal to 1 and never equal to 1 when it is equal to 4 since a single field can only have one value at a time. You probably mean OR rather than AND as using OR will return records where it is equal to 1 as well as records where it is equal to 4.

    SELECT * FROM `friends` WHERE `user_id` = '1' OR `user_id` = '4

  7. #7
    Join Date
    Jan 2003
    Location
    VA
    Posts
    419
    but, it didnt for me.. :\

    -- edit --
    NVM.. my bad thanks
    Last edited by Kyleva2204; 07-04-2006 at 12:07 AM.

Thread Information

Users Browsing this Thread

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

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