2016-09-09 71 views
0

我想更新我的數據庫中的字段。 我有兩個表和表字段像波紋管加入mysql的更新表

operations_per_assemblyoperation_id,is_mecahnical

operationsid,repair_type_id

現在我想更新is_mechanical場,其中repair_type_id =

我查詢

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 

請幫助我。

+0

你能指望什麼發生,和實際發生的情況? – Loopo

+0

我已編輯問題請檢查。 –

+0

'我做了幾個查詢,但沒有工作...... ...好的,但_what_不工作? –

回答

1

將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' 
+0

謝謝你的工作。 –

+0

不客氣。 –

0
UPDATE `operations_per_assembly` a 
JOIN `operations` b 
    ON a.operation_id = b.id 
SET a.is_mechanical = '4' 
WHERE codition (user proper condition) 
+0

不能正常工作.... –

+0

請給出一些解釋,而不僅僅是明碼 – andreas

0

在您使用operations_per_assemblyWHERE條款。 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