I have 2 tables. Customers and Orders.
My requirement is...
I would like to get the result like the following Customer Detail + HasOrders + Count(Orders)
I wrote
SELECT Customers.*
, CASE WHEN o.CustomerID IS NOT NULL THEN 1 ELSE 0 END HasOrders
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomersID
But it returns many rows. If the customer has 5 orders, it returns 5 rows for each Customer.
Could you please advise me? Thanks.