Jan
30
2006

Select Last Entries from MySQL

I have a log and I want to list the last time an entry was made by each of the users

SELECT user_id, MAX( log_date ) AS date,
DATE_FORMAT( MAX( log_date ) , "%M, %Y" ) AS english_date
FROM log_table
GROUP BY user_id

I’m not sure if this is the best way. The other options is to use WITH ROLLUP, I didn’t look into that option. This one seems to work, the only iffy part is the MAX(log_date), I may be pushing it just a bit ;)

Written by Aaron Wormus in: Cookbook, MySQL |

6 Comments »

  • ummm, isn’t this the *textbook* way to do this. in other words, i think this is pretty much how you’res supposed to do this.

    Comment | 2/2/2006
  • sexy latin woman…

    gimmemoney 534312 Description of sexy latin woman….

    Trackback | 19/1/2007
  • If you have an auto_increment column,

    SELECT * FROM my_table ORDER BY auto_increment_col DESC LIMIT 1

    Comment | 5/4/2007
  • Great wishes! Smith wesson model 64 lzomg

    Comment | 2/4/2008
  • insurance life fidelity life insurance

    Lovely. Made my day (which is saying something)

    Comment | 12/7/2008
  • paradise poker

    Thank you, I just wanted to give a greeting and tell you I like your website very much.

    Comment | 6/11/2008

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes