我遇到了一个奇怪的 SQL 错误。最后一个查询不起作用。当然,我可以将那个 DELETE 拆分为三个查询,但我真的想知道为什么 MySQL 不允许我这样做。
一个小例子:
(SELECT id FROM stairs WHERE building = 123)
UNION
(SELECT id FROM lift WHERE building = 123)
UNION
(SELECT id FROM qrcodeid WHERE building = 123)
作品!
DELETE FROM startpoint WHERE id IN (SELECT id FROM stairs WHERE building = 123)
也有效!
然而
DELETE FROM startpoint WHERE id IN (
(SELECT id FROM stairs WHERE building = 123)
UNION
(SELECT id FROM lift WHERE building = 123)
UNION
(SELECT id FROM qrcodeid WHERE building = 123)
)
引发错误
#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的“UNION (SELECT id FROM lift WHERE building = 123) UNION (SELECT id FROM qrc”附近使用正确的语法
任何人的线索?