I need a quick answer, please!

littlenicky

New member
Local time
Today, 19:24
Joined
May 20, 2003
Messages
7
Let's say I have in my database teachers, each one has one subject, and I want to find the most common subject... How do I do this with SQL?

SELECT MAX(*)
FROM Teachers
GROUP BY Subject

??????
 
Try something like this:
SELECT TOP 1 tblTeachers.Subject, Count(tblTeachers.Teacher) AS [Number]
FROM tblTeachers
GROUP BY tblTeachers.Subject
ORDER BY Count(tblTeachers.Teacher) DESC;

The TOP 1 part of the query will only show you the first item in the query results. Given that the results are sorted in descending order, it will give you the highest subject with the highest number of teachers.
 
Thanks for help!
I actually wanted ONLY the most common subject, but I see, I had to use COUNT()...
 

Users who are viewing this thread

Back
Top Bottom