Users Pricing

forum

home / developersection / forums / select cell from same column with max function in mysql

Select cell from same column with MAX function in mySql

Anonymous User 2081 17 Jul 2013
HI developers!

Table for example:

event_id| group_id | updated_at

1 | 1 |2012-01-02

2 | 1 |2012-01-01

3 | 2 |2012-01-01

4 | 2 |2012-01-02

5 | 3 |2012-01-01

I need select all event_id with max date, grouped by group_id. So right result will be:

event_id| group_id | updated_at

1 | 1 |2012-01-02

4 | 2 |2012-01-02

5 | 3 |2012-01-01

Can I select event_id, from the same row that MAX(updated_at) has been selected? 

SELECT event_id, group_id, MAX(updated_at)

FROM my_table

GROUP BY group_id;

Thanks in advance


I am a content writter !


1 Answers