繁体   English   中英

不能加入两个以上的表

[英]Can not join more than two table

我有3张桌子:

table1

fields : id, title, cat1_id

table2

fields : id, title, cat2_id

table3 

fields : id, title

我的SQL:

SELECT a.id, a.title, b.title, c.title 
FROM table1 AS a 
INNER JOIN table2 AS b ON b.id = a.cat1_id 
AND INNER JOIN table3 AS c ON c.id = b.cat2_id 
ORDER BY a.id DESC

它不起作用。

我尝试此SQL,它正在工作:

SELECT a.id, a.title, b.title, c.title 
FROM table1 AS a 
INNER JOIN table2 AS b ON b.id = a.cat1_id 
ORDER BY a.id DESC

但是双重INNER JOIN不起作用。

JOIN之前,您不需要使用AND来连接两个以上的表。

您的查询应为

SELECT a.id, a.title, b.title, c.title 
FROM table1 AS a 
INNER JOIN table2 AS b ON b.id = a.cat1_id 
INNER JOIN table3 AS c ON c.id = b.cat2_id 
ORDER BY a.id DESC

看看MySQL JOIN语法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM