mysql - selecting last n dated records for each in a group -


i hope can help. have table....

name    date    number john    2014-01-01    5 sally   2014-01-01    7 john    2013-12-24    2 sally   2013-12-24    7 john    2013-11-10    1 sally   2012-11-10    8 

i want latest 2 (or x) records each person eg

john    2014-01-01    5 john    2013-12-24    2 sally   2014-01-01    7 sally   2013-12-24    7 

i don't know start. if can shed light on grateful. (if have time) if explain solution learning purposes!

many thanks

jules

select x.*    my_table x    join my_table y      on y.name = x.name     , y.date >= x.date   group      x.name      , x.date  having count(*) <= 2   order      name,date desc; 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -