gpt4 book ai didi

mysql - 不能加入两个以上的表

转载 作者:行者123 更新时间:2023-11-30 23:15:52 24 4
gpt4 key购买 nike

我有 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 Syntax

关于mysql - 不能加入两个以上的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17895550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com