Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Unanswered: inner join losing some rows

    i have two tables, one with username/password information, and another with logs. in the log database one of the fields is the userid that triggered the log, where userid is the primary key of the users table.

    i am using the following query to join the username ( 'user' ) onto the result.

    SELECT logs.*,users.user from logs inner join users on logs.userid=users.userid order by id desc;

    the problem that i have is, if the log was triggered by a user not logged in, then the log has a userid of -1. when i run this query with the inner join, the id does not match anything so that log is not part of the returned rows.

    can anyone think of a way around this? thanks in advance.

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    select logs.*
         , users.user 
      from logs 
    left outer
      join users 
        on logs.userid = users.userid | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2003
    worked perfectly. thanks.

Posting Permissions

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