我有这样的疑问:
UPDATE `user`
SET mail='abc@abc'
WHERE id =
IF((SELECT admin FROM user WHERE id = '1') > 2,
(SELECT id FROM user WHERE id='2'),
(SELECT id FROM user WHERE id = '1')
)
因此我收到错误消息:
“您无法在FROM子句”
中为更新指定目标表'user'
我希望在'user'表中所有行中名为'mail'的tu更新列,其中'id'的行为1或2,具体取决于另一列名为'admin'的值。请帮助解决核心语法问题。
答案 0 :(得分:0)
在查询中多次使用同一个表时,需要使用别名:
SELECT * FROM users u1 INNER JOIN users u2 ON ...
这些子选择的重点是什么? 例如,这部分不是“(SELECT id FROM user WHERE id ='2')”等于只写“2”?
答案 1 :(得分:0)
UPDATE `user`
SET email='abc@abc'
WHERE id = (SELECT id FROM (SELECT IF((SELECT admin FROM user WHERE id = '1') > 2,
(SELECT id FROM user WHERE id = '2'),
(SELECT id FROM user WHERE id = '1')) AS id
) AS t
);