加入3表sql

时间:2016-05-02 05:57:38

标签: sql

table A(a_id)
table B (b_id)
table c(c_id , b_id, a_id);


select a.*, b.* , c* 
from c join b

我从这里感到困惑???

4 个答案:

答案 0 :(得分:2)

试试这个 -

SELECT * FROM A 
INNER JOIN C 
ON A.a_id = C.a_id 
INNER JOIN B
ON B.b_id = C.b_id;

答案 1 :(得分:0)

SELECT a.*, b.*, c*  
FROM c
LEFT JOIN b USING (b_id)
LEFT JOIN a USING (a_id);

答案 2 :(得分:0)

您可以在以下内容中使用INNERLEFTRIGHTFULL ... JOINS

SELECT * 
FROM A
LEFT JOIN B ON A.a_id = B.b_id
LEFT JOIN C ON B.b_id = C.c_id

答案 3 :(得分:0)

试试这个

SELECT A.* from tableA A
LEFT JOIN tableC C ON C.a_id = A.a_id
LEFT JOIN tableB B ON C.b_id = B.b_id