I have users table, each user have multiple records. I need to fetch the latest inserted records of each user. How is it possible using MySQL
users table
id name value updated_at
1 abc 123 2011-02-03
2 xyz qwe 2011-04-03
3 abc asd 2011-08-08
4 xyz poi 2011-08-07
My output should be
id name value updated_at
3 abc asd 2011-08-08
4 xyz poi 2011-08-07
I used Queries like
select id,name,value,updated_at from users group by name having max(updated_at)
select id,ep_name,position,max(updated_at) from test1 group by ep_name having max(updated_at)
But I was not able to get the desired result. I get the max(updated_at) value but not able to get the matching row. Please help
Note: Can this be done without using sub-query. Please help
Thanks in advance
Dan thanks a lot… 🙂 small change in group by to match my output