我在mysql中使用3个表的内连接时出错了

时间:2016-12-26 15:35:53

标签: mysql

你好我搜索了太多,我逐字检查了我的查询,但我无法修复此错误

我的疑问:

SELECT  color_table.color, size_table.size, size_table.length, size_table.sum, image_table.image_url, manto_table.name, manto_table.description, manto_table.price_sale, manto_table.price_coop,
 manto_table.price_single FROM size_table INNER JOIN
                         color_table ON size_table.color_id = color_table.id INNER JOIN
                         manto_table INNER JOIN
                         image_table ON manto_table.id = image_table.manto_id ON size_table.manto_id = manto_table.id; 

错误:

  

类型:PDOException
  代码:42000
  消息:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第5行的“ON size_table.manto_id = manto_table.id”附近使用正确的语法

3 个答案:

答案 0 :(得分:0)

像这样修改:

SELECT  color_table.color, size_table.size, size_table.length, size_table.sum, image_table.image_url, manto_table.name, manto_table.description, manto_table.price_sale, manto_table.price_coop,
 manto_table.price_single
 FROM size_table 
 INNER JOIN color_table ON size_table.color_id = color_table.id 
 INNER JOIN manto_table ON manto_table.id = image_table.manto_id 
 INNER JOIN image_table ON size_table.manto_id = manto_table.id; 

答案 1 :(得分:0)

重新组织你的句子:

    SELECT  color_table.color, size_table.size, size_table.length, size_table.sum, image_table.image_url, 
        manto_table.name, manto_table.description, manto_table.price_sale, manto_table.price_coop, manto_table.price_single 
 FROM size_table 
     INNER JOIN manto_table ON size_table.manto_id = manto_table.id
     INNER JOIN image_table ON manto_table.id = image_table.manto_id 
     INNER JOIN color_table ON size_table.color_id = color_table.id ; 

答案 2 :(得分:0)

SELECT color_table.color, 
       size_table.size, 
       size_table.length, 
       size_table.sum, 
       image_table.image_url, 
       manto_table.NAME, 
       manto_table.description, 
       manto_table.price_sale, 
       manto_table.price_coop, 
       manto_table.price_single 
FROM   size_table 
       LEFT JOIN color_table AS color_table
               ON size_table.color_id = color_table.id 
       LEFT JOIN manto_table  AS manto_table
               ON manto_table.id = image_table.manto_id 
       LEFT JOIN image_table  AS image_table
               ON size_table.manto_id = manto_table.id;