MySQL报错error near where not exists

5.6版本和5.7版本的写法不一样,高版本的不能到低版本执行。
5.7 版本

INSERT INTO USER (name, email)
    SELECT 'John', '[email protected]'
    WHERE NOT EXISTS
        (SELECT id FROM USER WHERE email = '[email protected]');

5.6版本

INSERT INTO USER (name, email)
    SELECT name, email
    FROM (SELECT 'John' as name, '[email protected]' as email) t
    WHERE NOT EXISTS (SELECT 1 FROM USER u WHERE u.email = t.email);

你可能感兴趣的:(错误汇总及解决办法,MySQL)