试图用mysql连接4个表

时间:2010-09-16 16:23:47

标签: sql mysql phpmyadmin

我正在尝试加入4个表但有问题。我的代码列在下面。

我收到的错误是

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON advancedcatalog_font_type.id = advancedcatalog_dimensions.font_type_id) LEFT ' at line 6

advancedcatalog_dimensions

id         |letter_id    |    font_type_id     |  font_size_id  |   dimensions   |   LED
----------------------------------------------------------------------------------------------
  1        |             |                     |                |                |
  2        |             |                     |                |                |
  3        |             |                     |                |                |
  4        |             |                     |                |                |

advancedcatalog_font_size

id         |font_size    |   
--------------------------
  1        |             |   
  2        |             | 
  3        |             |   
  4        |             |  

advancedcatalog_font_type

id         |font_name    |    
--------------------------
  1        |             | 
  2        |             |   
  3        |             |   
  4        |             |      

advancedcatalog_letter

id         |casing       |    letter           |  
------------------------------------------------
  1        |             |                     |  
  2        |             |                     |
  3        |             |                     |     
  4        |             |                     |      

查询有效:

   SELECT advancedcatalog_letter.letter, 
          advancedcatalog_dimensions.dimensions, 
          advancedcatalog_font_type.font_name       
     FROM (advancedcatalog_dimensions
LEFT JOIN advancedcatalog_letter ON advancedcatalog_dimensions.letter_id = advancedcatalog_letter.id) 
LEFT JOIN advancedcatalog_font_type ON advancedcatalog_font_type.id = advancedcatalog_dimensions.font_type_id
    LIMIT 0 , 400

NOT 的查询工作:

   SELECT advancedcatalog_letter.letter, 
          advancedcatalog_dimensions.dimensions, 
          advancedcatalog_font_type.font_name       
     FROM (advancedcatalog_dimensions
LEFT JOIN advancedcatalog_letter ON advancedcatalog_dimensions.letter_id = advancedcatalog_letter.id) 
LEFT JOIN (advancedcatalog_font_type ON advancedcatalog_font_type.id = advancedcatalog_dimensions.font_type_id)
LEFT JOIN advancedcatalog_font_size ON advancedcatalog_font_size.id = advancedcatalog_dimensions.font_size_id

1 个答案:

答案 0 :(得分:1)

advancedcatalog_dimensions.font_size_id不存在,您在第二个查询中引用它。