永发信息网

SQL数据库删除重复行保留一条记录,怎么写?

答案:6  悬赏:0  手机版
解决时间 2021-12-30 17:40
  • 提问者网友:世勋超人
  • 2021-12-29 23:54
如:
name age
张三 18
张三 18
李四 19
李四 19
李四 19
我想只保留一个张三、李四,怎么弄?注意没有主键。
最佳答案
  • 五星知识达人网友:狂恋
  • 2021-12-30 00:47
DISTINCT语句啊
全部回答
  • 1楼网友:荒野風
  • 2021-12-30 07:12
select name,age into newtable from table group by name,age
  • 2楼网友:山有枢
  • 2021-12-30 05:40
查出所有不重复记录重新建个表 create table tablename1 as select distinct * from tablename truncate掉原来表,把数据导回去。
  • 3楼网友:纵马山川剑自提
  • 2021-12-30 04:03
把没有重复的数据放到临时表 select distinct * into #a from biao 删除原表数据 delete table biao 把没有重复的插入到原表 insert into biao select *from #a
  • 4楼网友:長槍戰八方
  • 2021-12-30 03:18
select distinct * into A from biao delete table x insert into x select * from A
  • 5楼网友:十年萤火照君眠
  • 2021-12-30 02:21
删除重复记录,保留id最大的一条记录 delete from 表名 where name+age in (select name+age from 表名 group by name+age having count(*)>1) and id not in (select max(id) id from 表名group by name+age having count(*)>1)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯