1

我有 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不起作用。

4

1 回答 1

0

您不需要使用ANDbeforeJOIN来连接两个以上的表。

您的查询应该是

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

看看MySQLJOIN语法

于 2013-07-27T07:53:34.803 回答