title: Problems With Code Query Results, Using AdventureWorks & SQL Server
body: <p>I'm using AdventureWorks2012 database and Microsoft SQL Server 2012. I'm trying to return SalesOrderID, Year &amp; Month of Order Date, Total Due, Territory Group, Territory Name, State Shipping Order To, and the First and Last Name of Sales Rep assigned to the order. I used a bunch of joins and this is what I have in the code below.</p>
  
  <pre><code>SELECT          OH.SalesOrderID AS SalesOrderID,
                  YEAR(OH.OrderDate) AS [Year], 
                  MONTH(OH.OrderDate) AS [Month], OH.TotalDue AS TotalDue,
                  ST.[Group] AS [Group], 
                  ST.Name AS TerritoryName, SP.Name AS ShipState, 
                 (SalesP.FirstName + ' ' + SalesP.LastName) AS SalesRepName
  FROM            Sales.SalesOrderHeader OH
  INNER JOIN      Sales.SalesTerritory ST
  ON              OH.TerritoryID = ST.TerritoryID
  INNER JOIN      Sales.vSalesPerson SalesP
  ON              OH.SalesPersonID = SalesP.BusinessEntityID
  INNER JOIN      [Person].[StateProvince] SP
  ON              ST.TerritoryID = SP.TerritoryID
  INNER JOIN      [Person].[Address] A
  ON              OH.ShipToAddressID = A.AddressID
  GROUP BY        OH.SalesOrderID, OH.OrderDate, 
                  OH.TotalDue, ST.[Group], ST.Name, 
                  SP.Name, SalesP.FirstName, SalesP.LastName
  </code></pre>
  
  <p>When I execute the following code I get a bunch of SalesOrderID records and it seems to name every possible Ship State to the records. Basically I'm getting more records then I should. I'm not completely sure what I'm doing wrong in my code, I feel like my joins are right yet I'm not getting accurate data back. I'm looking for each SalesOrderID to have 1 result back, not many. Any help would be appreciated.</p>