First and Foremost, this is part of an assignment.
I am trying to use the COUNT function as part of a query in relation to the Northwind database. The query should retur
First, if you are learning SQL, you should learn proper explicit join
syntax. Simple rule: never use a comma in the from
clause.
Second, your query should use group by
instead of distinct
. In fact, it is more important to learn group by
than to learn distinct
, because you can generally write select distinct
using group by
.
So, where you are heading is:
SELECT c.CustomerID, c.CompanyName, COUNT(c.CustomerID)
FROM Orders o JOIN
Customers c
ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerID, c.CompanyName;