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

前端 未结 11 1349
野趣味
野趣味 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:56

    It's quite simple. For example, instead of writing:

    INSERT INTO x (id, parent_id, code) VALUES (
        NULL,
        (SELECT id FROM x WHERE code='AAA'),
        'BBB'
    );
    

    you should write

    INSERT INTO x (id, parent_id, code)
    VALUES (
        NULL,
        (SELECT t.id FROM (SELECT id, code FROM x) t WHERE t.code='AAA'),
        'BBB'
    );
    

    or similar.

提交回复
热议问题