views:

56

answers:

1

Suppose you have a table in SQL:

Prices
------
13.99
14.00
52.00 
52.00 
52.00 
13.99

How would you count the amount of times a DIFFERENT field has been entered in? Therefore an example of such a count would output:

13.99 - 2 times. 
14.00 - 1 times. 
52.00 - 3 times.

OR perhaps:

3 (i.e. 13.99, 14.00, 52.00)

Can anyone advise? Cheers.

+4  A: 

How about:

SELECT Prices, COUNT(*) FROM TheTable GROUP BY Prices

Can't say I've tried it on MySql, but I'd expect it to work...

Jon Skeet
Thank you very much indeed. I wasn't selecting it! Instead I was doing something like: SELECT * FROM TheTable COUNT(Prices). Cheers!
day_trader
`SELECT Prices, COUNT(*) as C FROM TheTable GROUP BY Prices ORDER BY C` in case you want to sort by count. :)
o.k.w
Thank you :). Just out of curiosity as well, let's say we have a 'TheTableTWO' and there's a column in there called 'Genre' which links to these price. How would I display that as well? therefore example output would be "13.99 || 65425 || Horror".
day_trader
Why don't you elaborate further on this question or ask a fresh new one and link to that from here? Reason being your original question is already has an accepted answer and it's kinda hard to answer via comment.
o.k.w
Nice, here's the linked question: http://stackoverflow.com/questions/1606062/count-instances-in-table1-and-link-to-table2
o.k.w