多个表联合查询

来源:百度知道 编辑:UC知道 时间:2024/06/16 18:20:08
有五个表,分别是A,B,C,D,E ,如果想从A,B,C,D,E表中分别取一些字段值,如从A中取a,从B中取b,从C中取c,从D中取d,从E中取e,而这五个表有共同的字段是bah,我想把他们联合成一个表查询,怎么写SQL语句啊?急急急

select A.a,B.b,C.c,D.d,E.e from A A,B B,C C,D D,E E where A.bah=B.bah and A.bah=C.bah and A.bah=D.bah and A.bah=E.bah

SELECT a,b,c,d,e
FROM select * from A,B,C,D,E
WHERE A.bah=B.bah and A.bah=C.bah and A.bah=D.bah and A.bah=E.bah ;

select A.a,B.b,C.c,D.d,E.e from A,B,C,D,E where A.bah=B.bah and A.bah=C.bah and A.bah=D.bah and A.bah=E.bah

select A.a,B.b,C.c,D.d,E.e from A,B,C,D,E where a.bah = b.bah,a.bah = c.bah,a.bah = d.bah,a.bah = e.bah

通过视图查简单方便。

SELECT A.bah,A.a,B.b,C.c,D.d,E.e
FROM (((A INNER JOIN B ON A.bah = B.bah) INNER JOIN C ON A.bah = C.bah) INNER JOIN D ON A.bah = D.bah) INNER JOIN E ON A.bah = E.bah;
不过,需要注意级联关系,以上代码是以A表作为主连接的