错在哪里?
谢谢!
SELECT Table.id,
Table.name,
Table.kommentar,
Table.pictureurl
WHERE Table.news_id = 5, //without this line the query works!
COUNT( Table1.comment_id ) AS numComments
FROM DATABASE.news_comments AS Table
LEFT JOIN DATABASE.news_comments_comments AS Table1
ON Table1.comment_id = Table.id
GROUP BY Table.id
ORDER BY Table.id DESC LIMIT 0,50
最佳答案
WHERE
子句应该在 FROM
子句之后
SELECT `Table`.id,
`Table`.name,
`Table`.kommentar,
`Table`.pictureurl,
COUNT( Table1.comment_id ) AS numComments
FROM DATABASE.news_comments AS `Table`
LEFT JOIN DATABASE.news_comments_comments AS Table1
ON Table1.comment_id = `Table`.id
WHERE `Table`.news_id = 5 // <=== HERE
GROUP BY `Table`.id
ORDER BY `Table`.id DESC LIMIT 0,50
还有一件事,你的别名 Table
应该用反引号转义,因为它是 Reserved Keyword in MySQL
关于php - MySQL 查询无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11879112/