You can't specify target table for update in FROM clause

前端 未结 11 1373
野趣味
野趣味 2020-11-21 22:46

I have a simple mysql table:

CREATE TABLE IF NOT EXISTS `pers` (
  `persID` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(35) NOT NULL,
  `gehalt` int(11         


        
11条回答
  •  时光取名叫无心
    2020-11-21 22:59

    If you are trying to read fieldA from tableA and save it on fieldB on the same table, when fieldc = fieldd you might want consider this.

    UPDATE tableA,
        tableA AS tableA_1 
    SET 
        tableA.fieldB= tableA_1.filedA
    WHERE
        (((tableA.conditionFild) = 'condition')
            AND ((tableA.fieldc) = tableA_1.fieldd));
    

    Above code copies the value from fieldA to fieldB when condition-field met your condition. this also works in ADO (e.g access )

    source: tried myself

提交回复
热议问题