Results 1 to 3 of 3
  1. #1
    Join Date
    May 2001
    Posts
    51

    Unanswered: Forcing return of a NULL?

    Hi all, consider the following SQL

    PHP Code:
    SELECT useridname FROM image WHERE userid IN (5,10
    Assume that there isnt a corresponding match for the userid 10, how can I force it to return a NULL for that value?

    ie.

    PHP Code:
    +--------------------+
    userid |  name  |
    +--------------------+
    5         |  dave   |
    10       |  NULL   |
    +--------------------+ 
    Cheers
    Taz

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you can do it with a left join from the users table, assuming you have a users table as well as the image table
    Code:
    select U.userid
         , I.name
      from users U
    left outer
      join image I
        on U.userid = I.userid
     where U.userid in (5,10)
    the users table has userids 5 and 10 but the image table might not have images for all users

    rudy
    http://r937.com/

  3. #3
    Join Date
    May 2001
    Posts
    51
    r937 u do get around dont you - you answer many of my questions at devshed too

    Anywho, i've managed to solved the problem another way (in code) as i cannot link via a user table for reasons best left un told

    Cheers again
    Taz

Posting Permissions

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