I have two tables :
teachers (teacher_id,teacher_name)
courses (teacher_id,course_id)
And I need to display names of the teachers, teaching maximum number of courses :
mysql> select teachers.teacher_name,tmp1.teacher_id,tmp1.cnt from (select max(tm p.cnt) as tmpMax from (select teacher_id,count(teacher_id) as cnt from courses g roup by teacher_id) as tmp) as tmp2,(select teacher_id,count(teacher_id) as cnt from courses group by teacher_id) as tmp1,teachers where tmp1.cnt = tmp2.tmpMax and teachers.teacher_id = tmp1.teacher_id;
I came up with the above query. Is there a simpler query for this problem?