Skip to content
Advertisement

SQL sort and count duplicate value

I need to count and sort student, how many course they took based on level like this:

I have 3 table student,Course,Registration

Member: student_id,student_name

Subject: subject_id,point_score

Registration: student_id,subject_id

What I currently have:

The problem with it, is that it only counts point 1 correctly and not point 2 and 3 and it doesn’t display the user if they do not take any subject like this:

Advertisement

Answer

Your sub-selects in the result columns need to join through the Registration table too.

To see students who don’t take any subject, change the joins in the main query to left outer joins, or, better yet, process point 1 the same way you process point 2 and 3.

Using sub-queries

Using outer joins and group by

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement