문제

Below statement will return values from OpenQuery(MYSQL).

Select * From OpenQuery(MYSQL, 'Select * From ResearchRpt') a
Where Not Exists (Select * From dbo.ResearchRpt where Id_report = a.Id_report)

I want to reversed it where the result values should be came dbo.ResearchRpt

Thank.

도움이 되었습니까?

해결책

Your query uses an anti-join. An anti-join can be implemented with LEFT JOIN + WHERE IS NULL just as well as with NOT EXISTS. So, convert your script to the LEFT JOIN version, swap the sides, and you are done:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top