mysql 根据两个字段值查询时如何去除重复数据
发布网友
发布时间:2022-04-24 07:57
我来回答
共5个回答
热心网友
时间:2022-04-08 05:37
删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)
and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)
看看这里:http://blog.csdn.net/anya/article/details/6407280
热心网友
时间:2022-04-08 06:55
假设表名为test:
select * from (select *, concat(name,code) as __f from test order by date desc) __t group by __f;
热心网友
时间:2022-04-08 08:29
这个语句是查询`Index`,sequence都相同的数据
select * from (select *, concat(`Index`,sequence) as __f from tbl_item order by sequence desc) __t group by __f having count(__f)>=2;
select * from tbl_item where sequence = 1465399887
热心网友
时间:2022-04-08 10:21
select distinct a.* from 表 a where a.date = ( select max(b.date) from 表 b where b.name = a.name and b.code = a.code )
自己试试
热心网友
时间:2022-04-08 12:29
select distinct id,date ,name,code from 表名 where 条件
在select 后加上一个distinct ,注意 distinct后面的字段不能是重复项的 比如id就可以 name code 就不行了