使用Where子句更新

时间:2012-10-30 06:24:13

标签: mysql

我在下面的查询中运行了这个错误:

UPDATE t_o
SET t_o.mlm_order_id = mt.order_id 
FROM temp_orders t_o, mlm_transaction mt
WHERE mt.v2_order_id = t_o.order_id

错误是:

#1064 - You have an error in your SQL syntax; check the manual 
that corresponds to your MySQL server version for the right syntax to use near
'FROM temp_orders t_o, mlm_transaction mt WHERE mt.v2_order_id = t_o.order_id' 
at line 3

请帮忙??

4 个答案:

答案 0 :(得分:1)

您使用的是SQLServer的语法。这相当于MySQL

UPDATE temp_orders t_o 
       INNER JOIN mlm_transaction mt
            ON mt.v2_order_id = t_o.order_id
SET    t_o.mlm_order_id = mt.order_id 

答案 1 :(得分:1)

还有一个版本 -

UPDATE temp_orders t_o, mlm_transaction mt
SET t_o.mlm_order_id = mt.order_id 
WHERE mt.v2_order_id = t_o.order_id

答案 2 :(得分:0)

你可以尝试这个,但未经测试:

UPDATE t_o
SET t_o.mlm_order_id = mt.order_id 
WHERE t_o.mlm_order_id = (SELECT mt.v2_order_id FROM mlm_transaction mt WHERE mt.v2_order_id = t_o.order_id)

答案 3 :(得分:0)

更新不使用FROM子句。

使用类似的东西:

UPDATE table_name SET column1=value1, column2=value2,... WHERE some_column=some_value