Reputation: 37
I have two tables, those are "Student" and "User". I want to select the first_name and Last_name from "Student" table which does not match with "Student_ID" of the user table.
SELECT student.student_id,
student.first_name,
student.last_name
FROM student,
USER
WHERE student.student_id != USER.student_id
Upvotes: 1
Views: 61
Reputation: 1131
Same as NOT IN
version but perform a little bit better. According to this: https://www.eversql.com/sql-syntax-check-validator/
SELECT
student.student_id,
student.first_name,
student.last_name
FROM
student
WHERE
NOT EXISTS (
SELECT
student_id
from
user
where
user.student_id = student.student_id
)
Upvotes: 2
Reputation: 909
Try using this query:
SELECT firstname,lastname
FROM Student
WHERE ID NOT IN(SELECT Student_ID from User);
Upvotes: 1