How to get highest count from list data in mysql?

Member

by larissa , in category: MySQL , 3 months ago

How to get highest count from list data in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , 3 months ago

@larissa 

To get the highest count from a list of data in MySQL, you can use the GROUP BY clause and the MAX() function.


Here's an example query to achieve this:


SELECT column_name, MAX(count_column) AS highest_count FROM table_name GROUP BY column_name;


Replace "column_name" with the name of the column you want to count and "count_column" with the column used to count the occurrences.


For example, if you have a table called "orders" with a column "product_name" and want to get the highest count of each product, you can use the following query:


SELECT product_name, MAX(count) AS highest_count FROM orders GROUP BY product_name;


This query will return the product name and the highest count for each product in the "orders" table.