SQL: GROUP BY : get last record from each group

Lets take example

tbl_user

id   name    sex

1    ram       male

2     sita      female

3      gita    female

4     hari      male

5     rina     female

 

to get the last entry of male and female use this query

SELECT MAX(id) as id, name, sex FROM tbl_user GROUP BY sex