1

我想知道另一个语法错误:

SELECT * FROM forum_question
    WHERE category='art'
        LEFT JOIN forum_answer ON (forum_question.id = forum_answer.question_id) 
    GROUP BY forum_question.id 
ORDER BY a_datetime DESC;

我得到的错误是:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“LEFT JOIN forum_answer ON (forum_question.id = forum_answer.question_id) GROUP B”附近使用正确的语法

谢谢。

4

3 回答 3

2

WHERE子句应该在子句之后FROMJOIN语句是FROM子句的一部分

SELECT  * 
FROM    forum_question
        LEFT JOIN forum_answer 
           ON (forum_question.id = forum_answer.question_id)
WHERE   category='art' 
GROUP   BY forum_question.id 
ORDER   BY a_datetime DESC;
于 2013-04-15T03:33:50.750 回答
1

WHERE子句应该在子句JOIN之后

SELECT  * 
FROM    forum_question
        LEFT JOIN forum_answer 
           ON (forum_question.id = forum_answer.question_id)
WHERE   category='art' 
GROUP   BY forum_question.id 
ORDER   BY a_datetime DESC;
于 2013-04-15T03:36:31.853 回答
0

首先join,然后使用where子句:

    SELECT * FROM forum_question
    LEFT JOIN forum_answer ON (forum_question.id = forum_answer.question_id) 
    WHERE forum_question.category='art'
    GROUP BY forum_question.id 
    ORDER BY a_datetime DESC;
于 2013-04-15T03:34:02.767 回答