您好,欢迎访问一九零五行业门户网

mysql删除子查询中的记录语句_MySQL

bitscn.com
mysql删除子查询中的记录语句
sql代码 delete from t_5star where locationid in ( select e.locationid from ( select a.* from t_5star as a , t_als_data as b where a.term = b.term ) e )
关键是子查询中的语句要放到单一e的表中
查询及删除重复记录的方法
(一)
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleid)来判断
sql代码 select * from people where peopleid in (select peopleid from people group by peopleid having count(peopleid) > 1) 2、删除表中多余的重复记录,重复记录是根据单个字段(peopleid)来判断,只留有rowid最小的记录delete from peoplewhere peopleid in (select peopleid from people group by peopleid having count(peopleid) > 1)and rowid not in (select min(rowid) from people group by peopleid having count(peopleid )>1)3、查找表中多余的重复记录(多个字段)select * from vitae awhere (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq having count(*) > 1)4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录delete from vitae awhere (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq having count(*) > 1)and rowid not in (select min(rowid) from vitae group by peopleid,seq having count(*)>1)5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录select * from vitae awhere (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq having count(*) > 1)and rowid not in (select min(rowid) from vitae group by peopleid,seq having count(*)>1)
(二)
比方说
在a表中存在一个字段“name”,
而且不同记录之间的“name”值有可能会相同,
现在就是需要查询出在该表中的各记录之间,“name”值存在重复的项;select name,count(*) from a group by name having count(*) > 1如果还查性别也相同大则如下:select name,sex,count(*) from a group by name,sex having count(*) > 1
bitscn.com
其它类似信息

推荐信息