If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > inner join losing some rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-05, 16:44
localhost localhost is offline
Registered User
 
Join Date: Sep 2003
Posts: 13
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.
Reply With Quote
  #2 (permalink)  
Old 02-24-05, 17:03
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
select logs.*
     , users.user 
  from logs 
left outer
  join users 
    on logs.userid = users.userid
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-24-05, 17:21
localhost localhost is offline
Registered User
 
Join Date: Sep 2003
Posts: 13
worked perfectly. thanks.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On