sql多表查询,会的速度!

来源:百度知道 编辑:UC知道 时间:2024/06/18 06:42:56
A表有字段。A001
B表有字段,B001,B002,B003
C表有字段。C001,C002,C003
D表有字段。D001,D002,D003
B001,C001,D001都跟A001有关联的。
现要显示B002,B003,C002,C003,D002,D003。查询语句怎么写?
这两种方法都不行,用过了。显示不出完整的。这样吧。

select G01006,A01030 from A010 where A010.A01000 in (select A00100 from A001) group by A010.A01000,A01030,G01006,A01015 order by A010.A01015
select A01300,A01305,G01301 from A013 where A013.A01300 in (select A00100 from A001) group by A01300,A01305,G01301 order by G01301
select G00411,G00406 from G004 where G004.G00400 in (select A00100 from A001) group by G00400,G00411,G00406,G00407 order by G00407

如何把这三条合并在一个表中。通过A001里的A00100这个字段

表1(可以是select ...from ...的SQL语句)
union all
表2
union all
表3

表合并:
表1(可以是select ...from ...的SQL语句)
union all
表2
union all
表3

select b.b002,b.b003,c.c002,c.c003,d.d002,d.d003
from a,b,c,d
where
b.001 = a.001 and
c.001 = a.001 and
d.001 = a.001

select * from A001 A
left join
(
select G01006,A01030 from A010 group by A010.A01000,A01030,G01006,A01015
) B
on A.A01000 = B.A01000
left join
(
select A01300,A01305,G01301 from A013 group by A01300,A01305,G01301

) C
on A.A00100 = C.A01300
left join
(
select G00411,G00406 from G004 group by G00400,G00411,G00406,G00407
) D
on A.A01000 = D.G00400

order by A010.A01015,G01301,G00407