Typically, using SELECT in a subquery to perform an UPDATE on the same table, such as:

UPDATE table1 AS target
SET field1 = (
    SELECT field2
    FROM table1 AS source
    WHERE source.id = target.id
)

is illegal in MySQL. To achieve the desired effect, you can perform an INNER JOIN in the UPDATE:

UPDATE table1 AS target
INNER JOIN table1 AS source USING(id)
SET target.field1 = source.field2

Leave a Reply