在mysql数据库中如何让某个字段有重复的只取一条

如题所述

第1个回答  2017-06-13
select top 1 id,name,age from 表 order by age desc按照年龄倒序排序,然后取第一条。考虑可能有多人年龄相同,如果都需取出,可以这样写:select id,name,age from 表 where age=(select max(age) from 表)
第2个回答  2017-06-13
-- 保留相同A值的最小id行

select *
from table_a a

where not exists (
select 1 from table_a b
where b.A = a.A
and b.id < a.id
)本回答被提问者采纳