I have been given the assignment to figure out what is wrong with the SQL Query below and how to optimize it. Here is what I have so far: 1) Incorrect syntax near the keyword 'FROM'. This means there is a trailing comma in the select list. 2) The Alias 'C' is not set in the query 3) Order by column ordinal is a bad practice I should avoid too except in adhoc querying 4) Instead of <> null, it should be is not null Anything else? SELECT C.ContactID, C.FirstName, C.LastName, SP.SalesPersonID, FROM Person.Contact A JOIN Sales.SalesPerson SP LEFT JOIN Sales.SalesTerritory ST ON ST.TerritoryID = SP.TerritoryID WHERE SP.SalesPersonNM <> NULL ORDER BY 1,2,3,4,5
I reckon you've nailed most of it. The only other thing I'd question is that there's no join condition for the join between Person.Contact and Sales.SalesPerson. That will join every contact to every sales person, which doesn't sound likely.