Reputation: 780
I have a mysql query that displays about 10 unique items from about 5,000 records..
SELECT DISTINCT (stockSymbol) AS myStock FROM 'USDJPY' ORDER BY myStock DESC
1865
1765
1632
etc..
my question is how can I make just one query that would DISTINCT but also (COUNT) how many records '1865' have and '1765' etc..
Upvotes: 0
Views: 29
Reputation: 204894
Group by the stockSymbol
and then use the count()
function on each group
SELECT stockSymbol,
count(*) as stockCount
FROM USDJPY
group by stockSymbol
ORDER BY stockCount DESC
Upvotes: 3