一个SQL删除语句的写法

[复制链接]
查看11 | 回复4 | 2010-2-2 12:12:50 | 显示全部楼层 |阅读模式
可以先找到你要删除记录的主键,然后按条件删除:delete from tawhereta.主键 in(select a.主键 from ta a, tb bwhere a.A = b.A and a.B = b.B)
回复

使用道具 举报

千问 | 2010-2-2 12:12:50 | 显示全部楼层
delete Tawhere exists(select 1 from TB where A=Ta.A and B=Ta.B)
回复

使用道具 举报

千问 | 2010-2-2 12:12:50 | 显示全部楼层
delete Tafrom Ta, Tbwhere Ta.A = Tb.A
and Ta.B = Tb.B如果不太灵的话,采用别名,如下书写delete Tafrom Ta x, Tb ywhere x.A = y.A
and x.B = y.B
回复

使用道具 举报

千问 | 2010-2-2 12:12:50 | 显示全部楼层
delete from Ta where exists(select A,B from Ta left join Tb on Ta.A=Tb.A and Ta.B=Tb.B)
回复

使用道具 举报

千问 | 2010-2-2 12:12:50 | 显示全部楼层
delete from ta where a in (select a from tb ) andb in (select b from tb)都不知你用的 是什么数据库
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行