gpt4 book ai didi

mysql - MySQL 中 UNION 附近的语法错误?

转载 作者:可可西里 更新时间:2023-11-01 07:02:14 28 4
gpt4 key购买 nike

SELECT * 
FROM Activity AA
WHERE AA.act_id IN
((SELECT A.act_id
FROM Activity A
WHERE A.user_id = 'lhfcws')
UNION
(SELECT J.act_id
FROM Joinin J
WHERE J.user_id = 'lhfcws'))
ORDER BY AA.act_time

ERROR MESSAGE: #1064 - 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 J.act_id FROM Joinin J WHERE J.user_id =
'lhfcws')) ORDE' at line 7

事件(act_id, user_id, act_name)
Joinin(act_id, user_id)

最佳答案

错误的原因是 select 语句周围的括号。你应该写成:

SELECT * 
FROM Activity AA
WHERE AA.act_id IN
(SELECT A.act_id
FROM Activity A
WHERE A.user_id = 'lhfcws'
UNION
SELECT J.act_id
FROM Joinin J
WHERE J.user_id = 'lhfcws')
ORDER BY AA.act_time

但请仔细阅读@Raphaël Althaus 改进查询的想法。

关于mysql - MySQL 中 UNION 附近的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10510335/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com