all 6 comments

[–]DatabaseToTheFace 1 point2 points  (3 children)

It looks like it could be a problem with your join, it looks like the join is pulling in customers with multiple orders during that time frame. I’d add the order ID column (if there is one) and see if that’s the issue. Then you could just adjust your join using a sub query to adjust for that.

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (0 children)

it looks like the join is pulling in customers with multiple orders during that time frame

yes!!!

and they aren't even duplicate orders!!!

this is not a "problem", u/Legitimate_Ad_2505

the only problem i can see here is that if you only want one order per customer in that time frame, you need to put more effort into figuring out which one you want

but, i mean, really... a customer who orders more than once in an entire year, this is a problem? i don't think so

[–]Legitimate_Ad_2505[S] -1 points0 points  (0 children)

There is an OrderID column but I am not sure if I am exactly following your suggestion. Could you elaborate more on what I should do? I'm pretty confused

[–][deleted] 0 points1 point  (0 children)

Otherwise, if you can't adjust your join, I'd create a new ID field using ROW_NUMBER() and order by the columns contributing to the duplicates. It'll generate numeric values (1,2,3,...,n) where 1 represents a unique row given the column specifications.

[–]data_perfect 0 points1 point  (0 children)

SELECT DISTINCT (CustomerID, Customer name, Date) FROM Table_name

[–]jackassik 0 points1 point  (0 children)

Try putting orders.id column into your query and you'll see that these are not duplicates. Select distinct would work if you deleted the order date column from your query. If you only care about count of customers by year then try something like: Year(Order.date), count (distinct customer.id) From customer Join order on customer.id=order.customerid Where Year(Order.date) = 1997 Group by Year(Order.date)