谢谢你 可是两张表的关系好象不清楚呀?比如说这样的句子: select id,name from table1 where (id not in(select id from table2 where ....)) ; 用exists 是不是一定比 in 快? 如果用exists 来改写,该怎么写?
比如: 学生表;student name sex 冰冰 男 心儿 女 大傻 男 ------------ 考试表:exam name score 冰冰 99 心儿 63 查询参加考试的学生 select name from student s where exists(select name from exam e where e.name=s.name)
谢谢风吹、驴驴,我知道了,其实exist 完成不了我希望的功能。
To z_yuer(鱼儿): 其实,你说的那句话可以改为: select id,name from table1 where not exists(select * from table2 where table1.id=table2.id and ...) 效率一定比not in的速度快.
可是两张表的关系好象不清楚呀?比如说这样的句子:
select id,name from table1 where (id not in(select id from table2 where ....)) ;
用exists 是不是一定比 in 快?
如果用exists 来改写,该怎么写?
学生表;student
name sex
冰冰 男
心儿 女
大傻 男
------------
考试表:exam
name score
冰冰 99
心儿 63
查询参加考试的学生
select name from student s where exists(select name from exam e where e.name=s.name)
其实,你说的那句话可以改为:
select id,name from table1 where not exists(select * from table2 where table1.id=table2.id and ...)
效率一定比not in的速度快.