Reputation: 1
I have 2 tables named student and teacher. I am using following query to get the output i.e
DELETE from student, teacher
USING student, teacher
WHERE teacher.teacher_id = student.teacher_id
AND teacher.teacher_id !=99
Problem is that when I run that query I get some other row in teacher table whose teacher_id is !=99 Actually in my student table some student not belong to any of the teacher.
Please help me out
Upvotes: 0
Views: 36
Reputation: 3659
You stated in your question that:
Problem is that when I run that query I get some other row in teacher table whose teacher_id is !=99
But in your query, you have the where condition:
teacher.teacher_id !=99
So I guess you want to delete STUDENTS
who belong to TEACHER 99
.
This should work:
DELETE FROM students
WHERE teacher_id = 99;
Or if I'm wrong and you want to delete all STUDENTS
who do not belong to TEACHER 99
, then:
DELETE FROM students
WHERE teacher_id <> 99;
Upvotes: 1