我的SQL语法中的另一个错误?

时间:2013-04-15 03:32:54

标签: mysql join

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

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服务器版本,以便使用正确的语法   靠近'LEFT JOIN forum_answer ON(forum_question.id =   forum_answer.question_id)第1行的B组

感谢。

3 个答案:

答案 0 :(得分:2)

WHERE子句应该在FROM子句之后。 JOIN语句是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;

答案 1 :(得分: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;

答案 2 :(得分: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;