使用此SQL语句时出现错误1064?

时间:2012-12-14 17:49:10

标签: mysql sql join

SELECT `news_posts`.`ID` , `category`.`ID` , `news_posts`.`Title` , `news_posts`.`Author` , `news_posts`.`Time` , `news_posts`.`Cat_ID` , `news_posts`.`Tags` , `news_posts`.`imageLocation` , `news_posts`.`thumbLocation` , `category`.`name`
FROM `news`.`category`
LEFT JOIN `category`.`ID` = `news_posts`.`Cat_ID`
LIMIT 0 , 30

这是它带来的错误

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在“。Cat_ID LIMIT 0,30'第16行附近使用正确的语法

1 个答案:

答案 0 :(得分:3)

您缺少表名news_postsON关键字。它应该是:

...
FROM `news`.`category`
LEFT JOIN news_posts ON `category`.`ID`  ...
...

像这样:

SELECT 
  `news_posts`.`ID` , `category`.`ID` , 
  `news_posts`.`Title` , `news_posts`.`Author` , 
  `news_posts`.`Time` , `news_posts`.`Cat_ID` , 
  `news_posts`.`Tags` , `news_posts`.`imageLocation` , 
  `news_posts`.`thumbLocation` , `category`.`name`
FROM `news`.`category`
LEFT JOIN news_posts ON `category`.`ID` = `news_posts`.`Cat_ID`
LIMIT 0 , 30