lundi 25 juillet 2016

SQL:How return record by look up max assign column?

data soure:

id  data1   data2
1   1       4
2   1       5
3   2       6
4   2       7

I need find data2 max and same data1. I hope return:

data1   id  data2
1       2   5
2       4   7

I try to: select data1, id, max(data2) from table1 group by data1, id. But it false.

Is there another way to do this?

Aucun commentaire:

Enregistrer un commentaire