title: TSQL Msg 1013 "Use correlation names to distinguish them."
body: <p>I looked trough many suggestions and can't figure how to solve this one for the last two hours.</p>
  
  <pre><code>SET DATEFORMAT DMY
  
  DECLARE @Source DATETIME = '01/01/2001'
  DECLARE @Destenaition DATETIME = '01/01/2020'
  
  SELECT ST.[Group],
         ST.Shop,
         SUM(ST.Purchased) AS Total,
         CHG.Charged
  FROM   (SELECT Personals.Groups.[Name]      AS 'Group',
                 Cards.vPurchases.PersonalID,
                 Personals.Registry.[Name],
                 SUM(Cards.vPurchases.Ammont) AS Purchased,
                 Cards.vPurchases.ShopName    AS Shop
          FROM   Cards.vPurchases
                 INNER JOIN Personals.Registry
                   ON Personals.Registry.Id = Cards.vPurchases.PersonalID
                 INNER JOIN Personals.Groups
                   ON Personals.Registry.[Group] = Personals.Groups.Id
                 INNER JOIN Personals.Groups
                   ON Personals.Groups.Id = CHG.GroupID
          WHERE  Cards.vPurchases.[TimeStamp] &gt;= @Source
                 AND Cards.vPurchases.[TimeStamp] &lt;= @Destenaition
          GROUP  BY Cards.vPurchases.PersonalID,
                    Personals.Registry.[Name],
                    Personals.Groups.[Name],
                    Cards.vPurchases.ShopName) ST,
         (SELECT PG.Id                      AS GroupID,
                 SUM(Cards.vCharges.Amount) AS Charged
          FROM   Cards.vCharges
                 INNER JOIN Personals.Registry
                   ON Personals.Registry.Id = Cards.vCharges.PersonalID
                 INNER JOIN Personals.Groups AS PG
                   ON Personals.Registry.[Group] = PG.Id
          WHERE  Cards.vCharges.[TimeStamp] &gt;= @Source
                 AND Cards.vCharges.[TimeStamp] &lt;= @Destenaition
          GROUP  BY Personals.Groups.[Name]) AS CHG
  GROUP  BY ST.Shop,
            ST.[Group]  
  </code></pre>
  
  <p>And then I get this error:</p>
  
  <blockquote>
    <p>Msg 1013, Level 16, State 1, Line 6 The objects "Personals.Groups" and
    "Personals.Groups" in the FROM clause have the same exposed names. Use
    correlation names to distinguish them.</p>
  </blockquote>
  
  <p>Thanks.</p>