Dzwebs.Net

撰写电脑技术杂文十余年

Sql查询语句性能优化对比

Admin | 2009-4-19 21:33:44 | 被阅次数 | 8762

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  假如:表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)


该杂文来自: 数据库Sql,VFP,Access

上一篇:Sql语句之查询员工信息详细实例

下一篇:Sql语句全局变量与局部常量的应用说明

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计