簡體   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