[英]Update table with join in mysql
我想更新數據庫中的字段。 我有兩個桌子和桌子領域像波紋管
表 operations_per_assembly
字段 operation_id,is_mecahnical
表 operations
字段 id,repair_type_id
現在我想更新is_mechanical
字段,其中repair_type_id
= 3
我的查詢
UPDATE
`operations_per_assembly`
JOIN `operations`
ON `operations`.`id` = `operations_per_assembly`.`operation_id`
SET `operations_per_assembly`.`is_mechanical` = '4'
WHERE `operations_per_assembly`.`operation_id` = `operations`.`id`
AND `operations_per_assembly`.repair_type_id = 3
請幫我。
將repair_type_id = 3條件放入聯接條件中。 這樣,您告訴您僅在repair_type_id = 3上加入,因此您只會獲得這些記錄。
UPDATE
`operations_per_assembly`
JOIN `operations`
ON `operations`.`id` = `operations_per_assembly`.`operation_id` AND `operations`.repair_type_id = 3
SET `operations_per_assembly`.`is_mechanical` = '4'
UPDATE `operations_per_assembly` a
JOIN `operations` b
ON a.operation_id = b.id
SET a.is_mechanical = '4'
WHERE codition (user proper condition)
在WHERE
子句中,您正在使用operations_per_assembly
。 repair_type_id
但您的operations_per_assembly
表中沒有repair_type_id
。
因此,請嘗試以下查詢:
UPDATE `operations_per_assembly` PAS
JOIN `operations` OPE ON OPE.`id` = PAS.`operation_id`
SET PAS.`is_mechanical` = '4'
WHERE OPE.repair_type_id = 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.