更新和左外部联接语句 [英] Update and left outer join statements

查看:83
本文介绍了更新和左外部联接语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有关联的表格,并且我想更新表A中的一个字段.是否可以将更新和联接合并到同一查询中?我用谷歌搜索,但没有找到任何可行的解决方案?

I have two tabels with a relation and I want to update a field in table A. Is it possible to combine update and join in the same query? I googled it but didnt find any working solution?

UPDATE md SET md.status = '3' 
FROM pd_mounting_details AS md 
LEFT OUTER JOIN pd_order_ecolid AS oe ON md.order_data = oe.id

我正在使用MS SQL

I'm using MS SQL

推荐答案

Update t 
SET 
       t.Column1=100
FROM 
       myTableA t 
LEFT JOIN 
       myTableB t2 
ON 
       t2.ID=t.ID

myTableA替换为表名,并将Column1替换为列名.

Replace myTableA with your table name and replace Column1 with your column name.

此后,只需将LEFT JOIN移至tableB.在这种情况下,t只是myTableA的别名. t2是联接表的别名,在我的示例中为myTableB.如果您不喜欢使用tt2,请使用您喜欢的任何别名-没关系-我只是喜欢使用那些别名.

After this simply LEFT JOIN to tableB. t in this case is just an alias for myTableA. t2 is an alias for your joined table, in my example that is myTableB. If you don't like using t or t2 use any alias name you prefer - it doesn't matter - I just happen to like using those.

这篇关于更新和左外部联接语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆