您的位置:首页 > 数据库

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 )
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: