您好我刚刚接触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,但我不知道正确的查询。请帮助我谢谢
答案 0 :(得分:1)
试试这个:
delete s
from subjcode s
join course c on s.cno = c.cno
join teacher t on c.tno = t.tno
where t.tname = 'MARSHALL';
答案 1 :(得分:1)
您可以使用加入删除:
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';
请参阅此参考: