mysql查询每个组最大的那条记录
假如有如下表:
解决方案一:
SELECT n1.* FROM news n1 LEFT JOIN news n2
ON (n1.name = n2.name and n1.id < n2.id)
where n2.id is null;
解决方案二:
select n1.* from
news n1
inner join
(select name, max(id) as maxid from news group by name) as n2 on
n1.id = n2.maxid