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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -