簡體   English   中英

MySQL 更新字段與來自兩個表的 WHERE

[英]MySQL update field with WHERE from two tables

UPDATE table1 
SET description = 'New description' 
WHERE language_code = 'en' AND table2 default_category_id = '11'

如何在 table1 和 table2 中正確使用它。 我只能在使用 table1 時解決它。

您需要在表之間建立關系。

update table1
set description = 'New desc'
where language_code = 'en'
and some_column in (select related_column 
                    from table2 
                     where default_category_id = '11')

嘗試在 2 個表之間使用連接

update table1 t1 join table2 t2 on t1.key = t2.key
set t1.desired_column = "value"
where t2.desired_column = "value"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM