Forum

Write a Query to Di...
 
Share:
Notifications
Clear all

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


Posts: 17
Topic starter
(@rahul)
Active Member
Joined: 3 years ago

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

2 Replies
Posts: 27
Admin
(@vinodkrsetty)
Eminent Member
Joined: 4 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

Self Learning Video Tutorials - Software Course

Posts: 18
(@jeevan303500)
Active Member
Joined: 2 years 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

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: