Skip to content
Advertisement

Get id with same value

I have a table as below:

May I know how can I get the studentNo who have exactly same course as student s001? Many thanks.

Advertisement

Answer

You want to count the number of courses for each student and then join the table to itself for different students taking the same course with the same total number of courses and then count that the total number of matched rows in the join equals total number of courses:

Which, for the (expanded) sample data:

Outputs:

STUDENTNO
s002

db<>fiddle here

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