SQL Server更新,包含2个左连接和一个where子句

时间:2016-11-22 19:23:43

标签: sql sql-server

我试图更新我的产品中的产品'其他2个表中没有的表。这些产品有一个独特的标识符' ean'。我的计划是与其他表进行2次左连接,然后更新其他ean字段是否包含null。顺便使用MS SQL Server。

表:product,table2,table3

  update product 
  set published = 0
  from p as product
   left join a as table2
     on p.ean = a.ean
   left join t as table3
     on p.ean = t.ean
  where t.ean is null and a.ean is null

既然它似乎不起作用,我做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为问题在于您的别名。

如果您的表格为product, table2, table3,则您的查询应为:

update P
set published = 0
from product as P
left join table2 as A
  on P.ean = A.ean
left join table3 as T 
  on P.ean = T.ean
where T.ean is null and A.ean is null