Unix Technical Forum

Make GROUP BY select entries i want

This is a discussion on Make GROUP BY select entries i want within the MySQL forums, part of the Database Server Software category; --> Hi Is there a way to tell group by to group by lets say user_id and to choice the ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:30 AM
Ralph
 
Posts: n/a
Default Make GROUP BY select entries i want

Hi

Is there a way to tell group by to group by lets say user_id and to
choice the entry where login_time is most recent?

Thank you
Ralph
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:30 AM
Bill Karwin
 
Posts: n/a
Default Re: Make GROUP BY select entries i want

Ralph wrote:
> Is there a way to tell group by to group by lets say user_id and to
> choice the entry where login_time is most recent?


Maybe you need to run GROUP BY on your newsgroup posts, too. ;-)

No, there's no way to tell GROUP BY to resolve the ambiguity for you.

Here's a solution for the question you asked:

SELECT t1.*
FROM tablex AS t1 LEFT JOIN tablex AS t2
ON t1.user_id = t2.user_id AND t1.login_time < t2.login_time
WHERE t2.login_time IS NULL

Regards,
Bill K.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:24 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com