Gacci
Gacci

Reputation: 1398

Select max from subquery group by

Is it possible to select max of subquery. I tried the following SELECT MAX(SELECT COUNT(lid) AS count FROM Lessons GROUP BY day) , but it obviously failed. Any suggestions?

enter image description here

Upvotes: 1

Views: 347

Answers (2)

Vincent Charette
Vincent Charette

Reputation: 136

SELECT MAX(myCount) FROM (SELECT COUNT(lid) AS myCount FROM Lessons GROUP BY day) AS sub Query

I believe this is what you are looking for.

Upvotes: 1

juergen d
juergen d

Reputation: 204756

Why not just

SELECT COUNT(lid) AS count 
FROM Lessons 
GROUP BY day
ORDER BY count desc
limit 1

Upvotes: 3

Related Questions