List:General Discussion« Previous MessageNext Message »
From:<jabbott Date:June 1 2005 3:49pm
Subject:query help?
View as plain text  
I have two tables, cutting out the extra stuff they boil down to:

users:
userID int,
username varchar(11),
realname varchar(40)

logins:
ID int,
lastLogin timestamp

So, what I am doing is:
 select user.id, username, realname, lastLogin
 from users left join logins on users.id = logins.id 
 group by username
 order by lastLogin DESC

What I want is all the users, no matter if they have logged in or not.  That is what the
left join does.  But, if they have logged in, I want the last login date.  Right now I
get the first login date.  Changing DESC to ASC only changes the display order of the
return set.  I have added DESC and ASC to the group by, but that doesn't work at all.

Advice?

--ja


-- 

Thread
query help?jabbott1 Jun
  • Re: query help?SGreen1 Jun
  • Re: query help?Digvijoy Chatterjee1 Jun
    • Re: query help?Alec.Cawley1 Jun
  • Re: query help?mfatene1 Jun