How can I rewrite the below query without the Limit clause?
SELECT project.title,
COUNT(project2manager.managerid) AS Cnt_Manager
FROM project2manager
JOIN project ON project2manager.projectid = project.projectid
GROUP BY project.title
ORDER BY Count_Manager DESC LIMIT 1;
+-----------------+-------------+
| project.title | Cnt_Manager |
+-----------------+-------------+
| City Scape | 8 |
+-----------------+-------------+
I tried to use the MAX clause but I keep getting the incorrect project title but the correct number of managers. what would be the best way to fix this?
SELECT title , MAX(Total)
FROM (SELECT project.title, COUNT(project2manager.managerid) AS Total
FROM project2manager
JOIN project ON project2manager.projectid = project.projectid
GROUP BY project.title) AS Result;
+-------------------------+------------+
| project.title | MAX(Total) |
+-------------------------+------------+
| Comic Con | 8 |
+-------------------------+------------+