How can I find the most frequent value in a given column in an SQL table?
For example, for this table it should return two since it is the most frequent value:
Try using the below code:
SELECT `column`, COUNT(`column`) AS `value_occurrence` FROM `my_table` GROUP BY `column` ORDER BY `value_occurrence` DESC LIMIT 1;
COUNT(`column`) AS `value_occurrence`
GROUP BY `column`
ORDER BY `value_occurrence` DESC
Note: You can replace the column and my_table. You can also increase 1 if you want to see the N most common values of the column.
Enroll yourself in the SQL server certification to learn in-depth about SQL statements, queries and become proficient in SQL.
Certification in Digital Marketing |
Certification in Big Data Analytics |
Certification in Cloud & Devops |
Certification in Full Stack Web Development
Big Data and Data Science Master’s Course |
Data Science Architect Master’s Program |
Cloud and DevOps Architect Master’s Course |
Artificial Intelligence Engineer Master’s Course |
Microsoft Azure Certification Master’s Training
Data Science Course Online |
Big Data Hadoop Certification Training |
Machine Learning Course Online |
Artificial Intelligence Course and Training |
Salesforce Certification Training: Administrator and App Builder |
Tableau Training and Certification Course |
Python Data Science Course & Training |
Ethical Hacking Course |
Business Analyst Course |
Courses in Cyber Security
© COPYRIGHT 2011-2021 INTELLIPAAT.COM. ALL RIGHTS RESERVED.
Download Salary Trends Now !
Learn how professionals like you got up to 100% Salary Hike.