var sidebar_align = 'right';
var content_container_margin = parseInt('350px');
var sidebar_width = parseInt('330px');
[PHP/SQL] Finding most occuring record
I am looking for a way in which to find the most commonly occurring record in my database. For example, if the contents of a simple db were...
...the result would be apple. I've managed to achieve the desired affect using a loop, working out the count of each entry. This however feels an extremely uneconomical way of doing things!
Is there any better way of doing this? Any help would be very greatly appreciated.
See the COUNT option of select
Originally Posted by jonathanbull
I don't have a database system to hand right now to check, but I think you need:
SELECT column_id, count(column_id) AS total
ORDER BY total DESC;
This would not work, this would be the output
Originally Posted by tim2718281
melon 7 etc.
This will work:
SELECT fruit, COUNT(fruit) as total FROM table_name GROUP BY fruit ORDER BY total DESC;
Thanks for the correction.
Originally Posted by crazylane
Actually, there could be a place on the forum for useful little sections of SQL like that.
Maybe a mysql sub-section? That would be great!
By zymic in forum Employment / Job Offers
Last Post: 04-11-2007, 08:02 PM
By jasonlambert in forum Ecommerce Hosting & Discussion
Last Post: 07-09-2004, 02:19 PM
By demonmoo in forum Ecommerce Hosting & Discussion
Last Post: 05-28-2004, 06:36 PM
By Senad in forum Hosting Software and Control Panels
Last Post: 02-25-2004, 11:41 PM
By LCHwebHost in forum Running a Web Hosting Business
Last Post: 03-11-2003, 07:26 PM