如题:最近在写sql server 的删除语句时,删除其中一个表,但是条件要关联到另外一张表,自然的要用到别名,但是执行时,提示a附近有语法错误的问题
delete from #ta where exists (select 1 from #tb b where #ta.id=b.id)
上面是可以的,但是如果用了#ta的别名,就不行了,提示 : 'a'附近有语法错误
delete from #ta a where exists (select 1 from #tb b where a.id=b.id)
正确写法:
delete a from #ta a where exists (select 1 from #tb b where a.id=b.id) --此种写法,实际删除的是表a