Friday, November 30, 2012

Row duplication - SQL limitation

-------------------------------------------------------------------------------
-- Here is an example of an SQL limitation.
-- Joining more than one table on the same columns that contains more than on
-- record per join criteria causes row duplication to occur.
-------------------------------------------------------------------------------
SELECT  t1.InvestorID , t2.Period , t3.Period
SELECT NumRecords = COUNT(*)
FROM    dbo.InvestorBase t1 WITH (NOLOCK)
        LEFT JOIN dbo.InvestorDetail1 t2 WITH (NOLOCK)
            ON t1.InvestorID      = t2.InvestorID 
            AND t1.Period         = t2.Period
        LEFT JOIN dbo.InvestorDetail2 t3 WITH (NOLOCK) 
            ON t1.InvestorID      = t3.InvestorID 
            AND t1.Period         = t3.Period

No comments:

Post a Comment