你能发现这个查询有什么问题吗?
SELECT * FROM requests
WHERE id = '".$id."'
LEFT JOIN request_data ON (requests.id = request_data.request_id)
GROUP BY requests.id
已经研究了一段时间,但似乎无法正确完成!
数据库如下所示:
-requests
-id
-another column
-and a third one
-request_data
-request_id
-key
-value
编辑:哦,对了,还有错误:
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 'LEFT JOIN request_data ON (requests.id = request_data.request_id) GROUP BY ' at line 3
有什么想法吗?
最佳答案
WHERE
位于错误的位置。
SELECT *
FROM requests
LEFT JOIN request_data ON (requests.id = request_data.request_id)
WHERE id = '".$id."'
您可能不需要 GROUP BY
,因为 WHERE
确保只会返回一个 id
,除非以某种方式您依赖于隐藏列功能(您不应该将其视为 the results are undefined )。
关于MySQL:使用 Join 时出现语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7715740/