id name age
1 a 33
1 b 34
1 c 43
1 d 44
2 aa 22
2 bb 33
3 aaa 23
3 bbb 24
-------------
要得到結果
1 d 44
2 bb 33
3 bbb 24
================================
SQL語句:
1、select id,name,age from table1 a group by id,name,age having age=(select max(age) from table1 where id=a.id)
2、select * from table1 a where age=(select max(age) from table1 where id=a.id)
3、select * from table1 a where not exists(select 1 from table1 where a.id=id and a.age<age)
注:父select中的字段也可以和子select中的字段聯繫