Encountered this while trying to get a diff on two large (20k records, no indexes) tables:
SELECT * FROM Morningstar.dbo.MStar_CompanyInfo as A
WHERE A.LocalName IS NOT NULL AND (A.ExchangeId+A.Symbol) NOT IN
(SELECT (B.ExchangeId+B.Symbol) FROM Companies.dbo.MStar_CompanyInfo as B)
takes in 15 minutes :(. Seems like the natural way to do it, no?
However, from advice here,
SELECT (A.ExchangeId+A.Symbol) as NewData,(B.ExchangeId+B.Symbol) as OldData, A.* FROM Morningstar.dbo.MStar_CompanyInfo as A
LEFT JOIN Companies.dbo.MStar_CompanyInfo as B
ON ((A.ExchangeId+A.Symbol)=(B.ExchangeId+B.Symbol))
WHERE (B.ExchangeId+B.Symbol) IS NULL AND A.LocalName is NOT NULL
returns same result instantly :D
No comments:
Post a Comment