选择查询更新时出现语法错误

时间:2015-12-07 23:06:42

标签: mysql

我在"FROM( SELECT"的第3行上遇到语法错误。我似乎无法弄清楚可能导致它的原因。

UPDATE lab_orders_lab_confirmationresults_c t
SET lab_orders_confirmationresultslab_confirmationresults_ida = foo.`1ID`
FROM(
        SELECT x.id as '1ID', y.id as '2ID'
        FROM lab_orders x 
        INNER JOIN lab_confirmationresults y ON x.orderid = y.orderid
        )foo
WHERE t.lab_orders_confirmationresultslab_confirmationresults_ida = 'undefined'
AND t.lab_orders_confirmationresultslab_confirmationresults_idb = foo.`2ID`

1 个答案:

答案 0 :(得分:0)

UPDATE ... FROM ...是无效的语法。你最接近的是

UPDATE table
  SET a_column = 
    (SELECT one_column
      FROM another_table
      WHERE some_condition
      LIMIT 1)

请注意,SELECT 必须只返回一行一列 才能生效。