I'm getting some unwanted results when grouping by two columns in SQL, here is the code;
SELECT i.*, o.mdate, u.name as producer_name, b.price as beat_price, COUNT(i.id) as sold_count
FROM #__mfs_items AS i
INNER JOIN #__mfs_users AS mu
ON i.producer = mu.id
INNER JOIN #__users AS u
ON i.producer = u.id
INNER JOIN #__mfs_beats AS b
ON i.beat_id = b.id
INNER JOIN #__mfs_orders AS o
ON i.order_number = o.order_number
GROUP BY i.producer
ORDER BY COUNT(*) DESC
LIMIT 10
Now what this does is get the top selling items and group them by their sellers. This unfortunately gathers every sale of every item for each seller and totals them, which is not what I want. When I try with GROUP BY i.beat_id
this gives me the desired results but there is one seller who takes all 10 top spots. When I try GROUP BY i.beat_id, i.producer
- this gives me the exact same results as grouping by i.beat_id
alone.
My aim is to have top selling items, but I want a unique seller for each spot. Can someone help me achieve this?
Thanks very much in advance