Sql- on update子查询不起作用

问题描述 投票:0回答:1
insert into users(email, is_CM, password, username)
    values ('[email protected]','N','*****','sidd@12345')
    ON DUPLICATE KEY UPDATE username=(SELECT username FROM users WHERE username = VALUES(username) OR email= VALUES(email));

我正在尝试运行此查询,但出现错误错误1093(HY000):您无法在FROM子句中指定目标表“用户”进行更新

请帮助我

java mysql sql jdbc
1个回答
0
投票

那里通常不使用子查询。我希望:

insert into users (email, is_CM, password, username)
    values ('[email protected]', 'N', '*****',' sidd@12345')
    on duplicate key update username = values(username), email = values(email));

这将现有行设置为传递给查询的值。

© www.soinside.com 2019 - 2024. All rights reserved.