A表和B表拥有相同的联合主键column1,column2, column3
正确的语句:
delete from TableA
where not exists (
select 1 from TableB b
where TableA.column1 = b.column1
and TableA.column2 = b.column2
and TableA.column3 = b.column3 )
and TableA.column4 = '20100804'
以上代码值得注意和强调的地方是 TableA 不能使用别名,例如以下编写就是错的:
delete from TableA a
where not exists (
select 1 from TableB b
where a
.column1 = b.column1
and a
.column2 = b.column2
and a
.column3 = b.column3 )
and a
.column4 = '20100804'
DB因为不识别TableA的别名a,导致语法错误。
本文介绍了一种SQL技巧,用于从表A中删除那些在表B中找不到对应联合主键(column1, column2, column3)的记录,并且表A的column4值为'20100804'。特别注意的是,在执行删除操作时,表A不能使用别名。
2007

被折叠的 条评论
为什么被折叠?



