0

我在同一台服务器上有两个数据库。我对每个正常工作的数据库都有两个简单的选择查询。但是,当组合成一个连接时,它们会失败。我想解决这个问题。

伪代码 -

select *
from (select columns from DB1) as D1
inner join 
select *
from (select columns from DB2 where some valid condition) as D2
on D1.column1 = D2.column1

错误 -

Incorrect syntax near the keyword 'SELECT'. (ie second "outer" select)
Incorrect syntax near the keyword 'on'.
4

2 回答 2

1

天哪——我所要做的就是这个——

select *
from (select columns from DB1) as D1
inner join 
--select *
--from 
(select columns from DB2 where some valid condition) as D2
on D1.column1 = D2.column1

请参阅注释行。删除它们,它应该可以工作。

注意,要包括从 D2 中选择的列,请将 D2 列放在最上面的 select 语句中。

select col1b, col2c
from (select col1a, col1b from DB1) as D1
inner join 
--select *
--from 
(select col2a, col2b, col2c from DB2 where some valid condition) as D2
on D1.col1a = D2.col2a

这将显示 col1b 和 col2c。

于 2013-10-15T21:14:10.807 回答
0
select *
from DataBaseName.ShemaName.TableName1 D1 inner join  DataBaseName.ShemaName.TableName2 D2
on D1.column1 = D2.column1
WHERE Somecondition
于 2013-10-15T20:47:08.933 回答