Sql查询语句性能优化对比
Admin
|
2009-4-19 21:33:44
|
TrackRecord:
1626
Times | Tag标签:数据库Sql,VFP,Access
打印本页
您当前所处的位置是:〖首页〗→【文章页】
本站共有16个图文教程栏目,请用心拜读!
本站提供经典的Excel公式函数实例,Word排版技巧,PPT教程;同时更兼有Flash,PowerPoint,数据库等技术文章。
假如:表table1、table2都有字段[姓名](varchar(10) )
问题:求table1中和table2中字段[姓名]不重复的记录,请写出你觉得最优的SQL语句。
1、查询花费0.0003秒
Select a.姓名 from table1 as a where not exists (select b.姓名 from table2 as b where a.姓名=b.姓名)
2、查询花费0.0002秒
Select a.姓名 from table1 as a where a.姓名 not in(select b.姓名 from table2 as b)
子查询—存在性测试中的子查询
存在性测试中的子查询只是检查子查询返回的结果集是否为空,使用的关键字为exists或not exists,它产生逻辑真值”True”或者假值”False”。
3、其它查询语句
写出一条SQL语句:取出表A中第31到第40记录(SQL Server,id(identity(0,1) primary key)。注意:id可能不是连续的)
1、select top 10 * from A where id not in(select top 30 id from A)
2、select top 10 * from A where id>(select max(id) from (select top 30 id from A) as A)
会员评论列表:

正在加载数据,请稍后……
针对本篇文章或本站,请您发表个人的建议或批评!