1、找出表中最小年龄的用户:
select min(age) from user ;
select top 1 age from user order by age;
select * from user where age<=all(select age from user);
2、找出名字重复的用户:
select * from user where name in (select name from user group by name having(count(name)>1));
3、复制表结构、拷贝表数据,联查:
select * into user1 from user where 1=0;
select * into user1 from user;
select * from user,user1,user2 where 关联条件;
4、SQL Server中创建临时表:
create table #temp(字段1 类型,字段2 类型...);临时表在表名前加#
5、最新写入的用户信息:
select * from user where createTime = (select max(createTime) from user);
6、取第5行到第7行的用户信息:
select * from user order by id limit 4,3;索引从4开始,取三个数据
slelect top 3 from user where id not in (select top 4 id from user order by id) order by id ;
原文:http://www.cnblogs.com/nowayZz/p/6234821.html