有以下MSSQL2008中一个名为AAA的数据库,TTT1表:
ttt1
公司名称 省份 市
------------------------------------------------------
山东工具制造有限公司出口部 山东 济宁
山东工具制造有限公司出口部 山东
曲阜圣都筷子店 山东 东昌府
济宁嘉富化肥有限公司 山东 济宁
济宁嘉富化肥有限公司 山东 济宁
要实现的目的:
凡是"公司名称"有重复的全部用SQL语句删除掉,实现后的效果如下:
ttt2
公司名称 省份 市
----------------------------------------------------------
曲阜圣都筷子店 山东 东昌府
请写得简单点,直接给执行语句,我不是很精通技术,太复杂的看不懂,谢谢.
解答:
delete a from ttt1 a where 公司名称in(select 公司名称from ttt1 group by 公司名称having count(*)>1);
delete from ttt1 where 公司名称in(select 公司名称from ttt1 group by 公司名称having count(*)>1);
delete ttt1 where 公司名称in(select 公司名称from ttt1 group by 公司名称having count(*)>1);
备注:MSSQL2005和2008不支持delete * from ttt1这样的删除语句,*号需要去掉。