Forum

Write a Query to Di...
 
Notifications
Clear all

Write a Query to Display the Course Name Registered by at least two Students. Sort the results based on Course Name.


Rahul Updhyay
Posts: 17
Topic starter
(@rahul)
Active Member
Joined: 12 months ago

Write a query to display the course name registered by at least two students.  Sort the results based on Course Name.

2 Replies
KV Kumar
Posts: 27
Admin
(@vinodkrsetty)
Member
Joined: 2 years ago

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

 
Reply
jeevan 123
Posts: 6
(@jeevan303500)
Active Member
Joined: 2 months ago

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

 
Reply
Share: