下面的语句将从 OpenQuery(MYSQL) 返回值。
Select * From OpenQuery(MYSQL, 'Select * From ResearchRpt') a
Where Not Exists (Select * From dbo.ResearchRpt where Id_report = a.Id_report)
我想在结果值应该出现的地方反转它 dbo.ResearchRpt
谢谢。
下面的语句将从 OpenQuery(MYSQL) 返回值。
Select * From OpenQuery(MYSQL, 'Select * From ResearchRpt') a
Where Not Exists (Select * From dbo.ResearchRpt where Id_report = a.Id_report)
我想在结果值应该出现的地方反转它 dbo.ResearchRpt
谢谢。
您的查询使用反连接。反连接可以用LEFT JOIN
+WHERE IS NULL
和. 来实现NOT EXISTS
。因此,将您的脚本转换为 LEFT JOIN 版本,交换边,您就完成了:
SELECT ms.*
FROM dbo.ResearchRpt ms
LEFT JOIN OPENQUERY(MYSQL, 'SELECT * FROM ResearchRpt') my
ON my.Id_report = ms.Id_report
WHERE my.Id_report IS NULL
-- Only exists
SELECT ms.*, my.Id_report
FROM dbo.ResearchRpt ms
LEFT JOIN OPENQUERY(MYSQL, 'SELECT * FROM ResearchRpt') my
ON my.Id_report = ms.Id_report
WHERE my.Id_report IS NOT NULL