MySQL如何选择OpenQuery不在语句中

时间:2012-05-02 07:55:04

标签: sql-server-2005 openquery

下面的语句将返回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

感谢。

2 个答案:

答案 0 :(得分:2)

您的查询使用反加入。可以使用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

答案 1 :(得分:1)

-- 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