带有LEFT JOIN的

时间:2016-11-21 10:27:35

标签: mysql

在下面的SQL查询中使用WHERE子句时出现语法错误。查询在没有where子句的情况下工作,where子句与没有连接的简单“SELECT * FROM”查询一起工作。原始查询使用PDO和绑定参数,但我在这个例子中使用直接SQL,因此我可以首先获得正确的语法。我哪里错了?

SELECT bk.*, au.author_firstname, au.author_surname, pu.publisher_name
FROM books bk
LEFT JOIN authors au ON bk.author_id = au.author_id
LEFT JOIN publishers pu ON bk.publisher_id = pu.publisher_id
ORDER BY title
WHERE bk.author_id = 13

1 个答案:

答案 0 :(得分:3)

   SELECT bk.*, au.author_firstname, au.author_surname, pu.publisher_name
     FROM books bk
LEFT JOIN authors au 
       ON bk.author_id = au.author_id
LEFT JOIN publishers pu 
       ON bk.publisher_id = pu.publisher_id
    WHERE bk.author_id = 13
 ORDER BY title

Where出现在ORDER BY之前。