我有三个 A、B、C 表。
如何一次加入 A 和 B 以及 B 和 C?
例如,如果我有这些表:订单、产品、用户,我想要这样的查询:
SELECT Product.title, User.username, Order.id
FROM Order
/* with this condition: */
Order.ProductID = Product.ID
Product.UserID = User.ID
在 from 子句中组合连接:
select *
from aaa a inner join bbb b
on a.x = b.y
inner join ccc c
on b.x = c.y
尝试:
SELECT Product.title, User.username, Order.id
FROM Order
INNER join Product ON Order.ProductID = Product.ID
INNER JOIN user ON Product.UserID = User.ID
select * from A a join B a on a.id = b.id /* condition for join*/ join C c on A.id = c.id /* condition for join*/ where ;//condition