[英]Can not join more than two table
I have 3 tables: 我有3张桌子:
table1
fields : id, title, cat1_id
table2
fields : id, title, cat2_id
table3
fields : id, title
My SQL : 我的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
it's not working. 它不起作用。
I try this SQL, it's working: 我尝试此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
but double INNER JOIN
does not work. 但是双重
INNER JOIN
不起作用。
You do not need to use AND
before JOIN
to join more that two tables. 在
JOIN
之前,您不需要使用AND
来连接两个以上的表。
Your query should be 您的查询应为
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
Have a look at MySQL JOIN
Syntax 看看MySQL
JOIN
语法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.