SQL学习 暑假第四天
2011-07-19 23:09
246 查看
1. 子查询
select * from ... where ... in select .. from ...
子查询 就是where后面接着 select 语句 例子:
select * from 辅导员信息 A where A.辅导员编号 IN( select B.辅导员 from 班级信息 B) --IN() 要加括号
2. EXISTS() NOT EXISTS() 关键字查询 用在where后判断 select 语句是否返回了结果
在用户登录系统这个 EXISTS()语句很有用例如
if EXISTS(Select * from user where user ID='232323' AND password='2rewfew' ) 在用户登录系统经常用到
declare @username nchar(20);
set @username ='王艳';
select * from 班级信息 where EXISTS( select * from 辅导员信息 A where A.姓名=@username)
3.
--嵌套子查询 查询中使用子查询 子查询中嵌套使用 子查询
select * from 辅导员信息 A where A.辅导员编号 IN (select B.辅导员 from 班级信息 B )
select * from ... where ... in select .. from ...
子查询 就是where后面接着 select 语句 例子:
select * from 辅导员信息 A where A.辅导员编号 IN( select B.辅导员 from 班级信息 B) --IN() 要加括号
2. EXISTS() NOT EXISTS() 关键字查询 用在where后判断 select 语句是否返回了结果
在用户登录系统这个 EXISTS()语句很有用例如
if EXISTS(Select * from user where user ID='232323' AND password='2rewfew' ) 在用户登录系统经常用到
declare @username nchar(20);
set @username ='王艳';
select * from 班级信息 where EXISTS( select * from 辅导员信息 A where A.姓名=@username)
3.
--嵌套子查询 查询中使用子查询 子查询中嵌套使用 子查询
select * from 辅导员信息 A where A.辅导员编号 IN (select B.辅导员 from 班级信息 B )
相关文章推荐
- SQL学习 暑假第四天
- java学习 暑假第四天 包。。。
- Sql学习第四天――SQL 关于with cube,with rollup和grouping解释及演示
- java学习 暑假第四天 包。。。
- Sql学习第四天——SQL 关于with cube ,with rollup 和 grouping
- T-SQL学习第四天
- 五个知识体系之-SQL学习-第四天
- Sql学习第四天——SQL关于with cube,with rollup和grouping
- web flask 框架 表单学习与sql 第四天吧。。
- Sql学习第四天――SQL 关于with cube,with rollup和grouping解释及演示
- Linq to sql学习之查询句法
- Java学习总结第四天Java运算符
- SQL基础学习_02_查询
- [暑假学习笔记]零、前述
- ORACLE基础学习(2)-SQL语句
- sql 学习笔记 p46
- 第63课:Spark SQL下Parquet内幕深度解密学习笔记
- sql语句学习
- 黑马程序员之SQL server基础学习笔记(三)
- windows下sql学习(一):mysql安装