SQLは2つのテーブルの更新ステートメントに関連付けられています(転送)

再投稿元: SQL Update: 1 つのテーブルのデータを使用して別のテーブルを更新し更新により 2 つのテーブルが関連付けられます

基本的に、select でサポートされている関連付けおよびサブクエリ操作は、update ステートメントで使用できます。

where 条件でサブクエリを使用する

update a
set a.age =1
where id in (select device_id from b)

where 条件と set ステートメントの両方でサブクエリを使用する

update a
set a.gender = (select sex from b where a.id= b.stu_id) 
where id in (select stu_id from b)

参加する

テーブル構造

テーブル A の列 mc をテーブル B のデータで更新します (列 mc)

SQLサーバー

update A SET A.mc = b.mc FROM A ,B WHERE  A.bmbh = B.bmbh and A.xmbh = B.xmbh;

アクセス

update A, B  set A.mc = B.mc where A.bmbh = B.bmbh and A.xmbh = B.xmbh;

または

update A INNER JOIN B ON A.bmbh = B.bmbh AND A.xmbh = B.xmbh SET A.mc = B.mc;

再投稿元: SQL Update: 1 つのテーブルのデータを使用して別のテーブルを更新し更新により 2 つのテーブルが関連付けられます

おすすめ

転載: blog.csdn.net/qq_41767116/article/details/132074945