[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.