这个 UNION ALL mysql 查询有什么问题?
SELECT 'Q' AS TYPE,
q.question AS value,
q.date
FROM questions q
WHERE q.user_id =39
UNION ALL
SELECT 'A' AS TYPE,
q.question AS value,
a.date
FROM answers a,
questions q
WHERE a.question_id = q.id
AND WHERE a.user_id =39
ORDER BY `date` DESC
数据库设计:
- 问题{id,user_id,问题,日期}
- 答案{id,question_id,user_id,答案,日期}
错误:
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'WHERE a . user_id = 39 ORDER BY
日期
DESC
SELECT 'Q' AS TYPE,
q.question AS value,
q.date
FROM questions q
WHERE q.user_id =39
UNION ALL
SELECT 'A' AS TYPE,
q.question AS value,
a.date
FROM answers a,
questions q
WHERE a.question_id = q.id
AND WHERE a.user_id =39
ORDER BY `date` DESC
database design:
- questions{id,user_id,question,date}
- answers{id,question_id,user_id,answer,date}
error:
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 'WHERE a . user_id = 39 ORDER BY
date
DESC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查询的下部有两个 WHERE 子句。您需要从字面上删除最后一个单词 WHERE。错误描述就是您所需要的。
There are two WHERE-clauses in the lower part of the query. You need to literally remove just the last word WHERE. The error description is all you need.
“WHERE”出现两次。其中 x = ..... 且 ....
"WHERE" appears twice. Where x = ..... AND ....
有一个额外的地方 a.user_id=39。您仅在子句开头使用关键字 WHERE (a.question_id = q.id AND a.user_id = 39)
Had an extra where a.user_id=39. You only use the keyword WHERE at the beginning of the clause (a.question_id = q.id AND a.user_id = 39)
正如错误试图解释的那样:对于第二个选择,您只需要输入一个“WHERE”。
As the error tries to explain: For the second select you only need to put one "WHERE".