如何编写一个SELECT
查询,从不同的表和不同的数据库中选择值?
e.g
dbSALES
tbSalesOrder
dbSHIPMENT
tbShipmentDetails and tbShipmentMaster.
我的主要目标是加入所有表格
答案 0 :(得分:0)
我相信这通常会奏效:
SELECT ...
FROM dbSALES.tbSalesOrder
JOIN dbSHIPMENT.tbShipmentDetails ON ...
JOIN dbSHIPMENT.tbShipmentMaster ON ...
答案 1 :(得分:0)
假设您使用的是SQL Server。
它将使用普通SELECT
和JOIN
编写,但使用完全限定表格的名称,例如database.schema.object_name
。像这样:
SELECT
...
FROM dbSALES.tbSalesOrder
INNER JOIN dbSHIPMENT.tbShipmentDetails ...
答案 2 :(得分:0)
在SQL Server中,您可以使用以下内容:
SELECT [column-list] FROM dbSales.[schema].tbSalesOrder SO JOIN dbSHIPMENT.[schema].tblShipmentDetails SD ON SD.[join_column] = SO.[join_column] JOIN dbSHIPMENT.[schema].tbShipmentMaster SM ON SM.[join_column] = SD.[join column]
答案 3 :(得分:0)
试试这个。
select * from dbSales.tbSalesOrder a
join dbShipment.tbShipmentDetails b on (a.field1=b.field1 and ......)
join dbShipment.tbShipmentMaster c on (b.field1=c.field1 and ......)
where a.field1=xxxx and b.field2=yyyy