下面的查詢工作:包裝SQL查詢導致語法錯誤
SELECT DISTINCT `number`
FROM `employee`
WHERE `number` IN
(SELECT `department_manager`
FROM `department`)
UNION
(SELECT DISTINCT `manager`
FROM `employee`
WHERE `manager` IS NOT NULL)
但只要我包裹查詢用括號它不工作了:
(SELECT DISTINCT `number`
FROM `employee`
WHERE `number` IN
(SELECT `department_manager`
FROM `department`)
UNION
(SELECT DISTINCT `manager`
FROM `employee`
WHERE `manager` IS NOT NULL))
曹景偉語法錯誤:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
在圓括號中包裝其他選擇查詢不會導致問題,例如:
(SELECT DISTINCT number FROM johnson.employee);
這些有什麼區別?
圍繞第二括號中的第一個查詢選擇已經無用的,沒有必要的。 – 2014-09-29 17:12:36
那麼不要把它包裹在圓括號裏? – 2014-09-29 17:18:04
@MichaelMcGriff如果我真的知道爲什麼會不會更有趣? – 2014-09-29 17:18:43