Write a query to display the course name registered by at least two students. Sort the results based on Course Name.
Hi Rahul,
I hope this query will give you the expected output. Please check and let me know
Select a.CourseName,b.FirstName,
c.Count(CourseID)
From
Course a,
Student b,
Registration c
group by a.CourseName, b.FirstName
Having Count(CourseID)=>2
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