您好,我是sql的新手,我很难删除记录。我需要从教师为“ MARSHALL”的subjcode表中删除所有记录。我使用此查询,但我无法正常工作:
delete
from subjcode
where (
select sa.sno
from subjcode sa,
teacher,
course
where teacher.tname = 'MARSHALL'
and teacher.tno = course.tno
and course.cno = sa.cno
) = subjcode.sno;
有表及其列:
subjcode: sno,cno,score
course: cno,tno,cname
teacher:tno,tname
我知道我所需要的只是tname,tno和cno,但我不知道正确的查询。请帮我谢谢
最佳答案
您可以使用join删除:
delete s
from subjcode s
join course c on s.cno = c.cno
join teacher t on t.tno = c.tno
where t.tname = 'MARSHALL';
请参阅此作为参考:
https://dev.mysql.com/doc/refman/5.7/en/delete.html
关于mysql - 如何删除单个表中涉及多个表的行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43072541/