MS SQL Server/Left join with groups
I am trying to perform a select with left join along with group by clause but i keep getting the message
"Column 'Orders.OrderID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. "
the query i am trying is
LEFT JOIN Orders
Group By Customers.ContactName;
i am using the standard Northwind sample database as the database,
GROUP BY requires all columns in the select to either have those mentioned in the GROUP BY clause or have aggregate function with those in the SELECT.
In your query, there are three columns in the select and there are no columns with aggregate (SUM, AVG, MAX etc.), while there's only one column in the GROUP BY. This mandates the rest two columns of SELECT to either have aggregate on those or be in the group by or to be removed from SELECT totally.
Feel free to followup.