作业帮 > 综合 > 作业

delete from msgmessag where exists (select 1 from msgmessag

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/01 16:05:38
delete from msgmessag where exists (select 1 from msgmessag where contentid='9')
在oracle中执行这条语句后的结果不是应该:将msgmessag中contentid='9'的记录删除掉么?怎么会把msgmessag 这个表中所有的记录都给删掉呢?
是会删除所有记录的,因为子查询这条记录是存在的.
你的查询可解释为删除 如果子查询中(msgmessag表)存在等于9的记录,就删除主表msgmessag.
应该与删除表建立关联:
delete from msgmessag where exists (select 1 from msgmessag A where contentid='9' AND A.CONTENTID=MSGMESSAG.CONTENTID)
该查询可解释为:删除 如果msgmessag(主查询)CONTENTID字段与子查询相同就删除该记录.(子查询中的CONTENTID字段等于9并且与主查询相同).
效果等同于delete from msgmessag where contentid='9