I have a table named "places" that has similar values in one column like in the following data, and I want to find the distinct values, display their count/number of occurrences, sort them in descending order, and limit results to only three values:
name residents
San Andres 50
San Felipe 143
San Juan 810
San Pablo 352
San Pedro 229
San Vicente 62
Santa Maria 500
San Juan 129
San Andres 88
Santo Rosario 55
San Juan 717
San Vicente 111
I want the result to be:
San Juan 3
San Andres 2
San Vicente 2
I tried the following statement but it gives a different result:
SELECT DISTINCT(name) AS distinctName, COUNT(name) FROM place ORDER BY COUNT(distinctName) DESC LIMIT 3;