bradley Lucas bradley Lucas - 3 months ago 18
SQL Question

Output student number that exists only on primary key but doesn't exist on foreign key

I have two tables

Student
table


  • student number primary key



Grade
table


  • student number foreign key



I want to display only students that exist in the
student
table but don't exist in the
grade
table

Answer

This way you can select all students that are not found (by their id) in the grade table.

SELECT * 
FROM student 
WHERE id NOT IN (SELECT student_id FROM grade)
Comments