Write a Query to Display the Course Name Registered by at least two Students. Sort the results based on Course Name.
Write a query to display the course name registered by at least two students. Sort the results based on Course Name.
I hope this query will give you the expected output. Please check and let me know
group by a.CourseName, b.FirstName
Order by Course_Name DESC
You may also try this one.
Assume that there are three tables in my database.
Courses, Registration, and Students
Students has StudentID, StudentName columns
Courses have also CourseID, CourseName, and also there is a third table joined with the Students and Courses table, etc.
Registration : StudentID, CourseID
One Student can enroll in one or many courses.
Now we would like to find out the name of the Students registered in only one course.
You can write this query.
SELECT S.StudentID, S.StudentName
FROM Students S
INNER JOIN registration R ON S.StudentID = R.StudentID
GROUP BY S.StudentID, S.StudentName
HAVING COUNT(*) = 1