php - MySQL Getting last 5 entries for each id in a SELECT - WHERE IN statement -


i select last 5 entries each of id in select - in statement.

//how last 5 entries each id select * table1 id in (111,222,333,.....) order date desc limit 5 

edit: example of how data structure

id  date    name 111 7-nov   anna 111 8-nov   belle 111 9-nov   mary 111 10-nov  john 111 11-nov  robert 111 12-nov  gary 111 13-nov  rick 222 8-apr   sarah 222 9-apr   lee 222 10-apr  margaret 222 11-apr  lisa 222 12-apr  222 13-apr  alex 222 14-apr  kelly 222 15-apr  lucas 

desired results

id  date    name 111 13-nov  rick 111 12-nov  gary 111 11-nov  robert 111 10-nov  john 111 9-nov   mary 222 15-apr  lucas 222 14-apr  kelly 222 13-apr  alex 222 12-apr  222 11-apr  lisa 

i not sure can done in mysql. have tried looking @ answers posted , can't find answers.

it pseudo code, think works. try this

select

id,

substring_index(group_concat( some_column_1 order date desc),',',5)

substring_index(group_concat( some_column_2 order date desc),',',5)

....

from table id in (111,222,333,.....) group id;

it not want. showing how use group_concat , substring_index function, apply this, can find answer.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -