Reputation: 107
I have two tables I want to display student without results
Student tables
Sname snumber
A 1
B 2
C 3
G 4
And results table
Snumber marks
1 90
4 60
I have the following code
Select student.sname from student
Join results
On student.snumber=results.snumber
Its showing students With results. I want student without results which is B and C
Upvotes: 0
Views: 40
Reputation: 2104
Try this,
Select student.sname
from student
LEFT Join results
On student.snumber=results.snumber
WHERE results.snumber is null
If you want all the students then remove the where clause.
Upvotes: 3
Reputation: 9143
After LEFT JOIN
solution (@Jatin Patel), you can see NOT EXISTS
one:
SELECT *
FROM Students S
WHERE NOT EXISTS(SELECT * FROM results R WHERE S.snumber=R.snumber)
Upvotes: 2