SQL JOIN与OPENQUERY

时间:2016-07-27 14:34:43

标签: sql sql-server join left-join openquery

如何使用打开的查询正确加入查询? 这是我的查询现在如何布局。作为OPENQUERY一部分的查询单独工作。

Select d.* from db.dbo.table d left join (select * from OPENQUERY(otherSource,' --working query SELECT... left join... inner join..') OQ ON d.col1 = OQ.col1

我正在捕捉错误'Incorrect syntax near 'ON'.

2 个答案:

答案 0 :(得分:1)

此语法对我有用:

select 
   a.id, b.ItemId, a.Name, b.[Description]
from 
   [A_Database]..tblA a
inner join 
   openquery([linkedServerDbName], 'select * from [B_Database]..[TableToJoin]') b
ON 
   a.id = b.ItemId

答案 1 :(得分:0)

您可能需要撤消它,从OPENQUERY执行SELECT。所以类似的东西:
SELECT * FROM OPENQUERY(remotesource,'SELECT blahblah from tableA)A
RIGHT JOIN tableB B ON B.col1 = A.col1