MySQL UPDATE:每个派生表必须有自己的别名

时间:2016-11-18 11:52:27

标签: mysql sql innodb

MySQL中的以下查询:

UPDATE e_element e1
 INNER JOIN
 (
 SELECT DVAL
 FROM e1
  INNER JOIN  e_element e2
   ON e1.ENT_OID = e2.ENT_OID
  WHERE
   e2.META_OID = 336810 AND
   e1.META_OID = 359462 AND
   e1.DVAL = '0001-01-01 00:00:00'
 )
SET e1.DVAL = e2.DVAL;

引发以下错误:

Error Code: 1248
Every derived table must have its own alias

我用两个select语句尝试了几个不同的选项,但我永远无法达到我想要的结果,即在给定条件的情况下将值从e2复制到e1

2 个答案:

答案 0 :(得分:1)

您的查询有多个错误。 。 。大括号,没有on子句,对表别名的不恰当引用,错误位置的where子句。

也许你打算:

UPDATE e_element e1 INNER JOIN
       e_element e2
       ON e1.ENT_OID = e2.ENT_OID
    SET e1.DVAL = e2.DVAL
WHERE e2.META_OID = 336810 AND
      e1.META_OID = 359462 AND
      e1.DVAL = '0001-01-01 00:00:00';

答案 1 :(得分:1)

尝试此查询

UPDATE e_element e1 
  INNER JOIN e_element e2
       ON e1.ENT_OID = e2.ENT_OID
    SET e1.DVAL = e2.DVAL
WHERE e2.META_OID = 336810 
      AND e1.META_OID = 359462 
      AND e1.DVAL = '0001-01-01 00:00:00';

希望这会帮助你。