没有合适的资源?快使用搜索试试~ 我知道了~
sql语句中join的用法
需积分: 46 3 下载量 174 浏览量
2011-11-08
13:49:33
上传
评论 1
收藏 4KB TXT 举报
温馨提示
试读
4页
sql语句中join的用法 sql语句中join的用法
资源推荐
资源详情
资源评论
关于sql语句中的连接(join)关键字,是较为常用而又不太容易理解的关键字,下面这个例子给出了一个简单的解释,相信会对你有所启示。
--建表table1 table2:
create table table1(id int name varchar(10))
create table table2(id int score int)
insert into table1 select 1 ' lee'
insert into table1 select 2 ' zhang'
insert into table1 select 4 ' wang'
insert into table2 select 1 90
insert into table2 select 2 100
insert into table2 select 3 70
如表
-------------------------------------------------
table1 | table2 |
-------------------------------------------------
id name | id score |
1 lee | 1 90 |
2 zhang | 2 100 |
4 wang | 3 70 |
-------------------------------------------------
以下均在查询分析器中执行
一、外连接
1.概念:包括左向外联接、右向外联接或完整外部联接
2.左连接:left join 或 left outer join
(1)左向外联接的结果集包括 left outer 子句中指定的左表的所有行,而不仅仅是联接列所匹配的行。如果左表的某行在右表中没有匹配行,则在相关联的结果集行中右表的所有选择列表列均为空值(null)。
(2)sql语句
--建表table1 table2:
create table table1(id int name varchar(10))
create table table2(id int score int)
insert into table1 select 1 ' lee'
insert into table1 select 2 ' zhang'
insert into table1 select 4 ' wang'
insert into table2 select 1 90
insert into table2 select 2 100
insert into table2 select 3 70
如表
-------------------------------------------------
table1 | table2 |
-------------------------------------------------
id name | id score |
1 lee | 1 90 |
2 zhang | 2 100 |
4 wang | 3 70 |
-------------------------------------------------
以下均在查询分析器中执行
一、外连接
1.概念:包括左向外联接、右向外联接或完整外部联接
2.左连接:left join 或 left outer join
(1)左向外联接的结果集包括 left outer 子句中指定的左表的所有行,而不仅仅是联接列所匹配的行。如果左表的某行在右表中没有匹配行,则在相关联的结果集行中右表的所有选择列表列均为空值(null)。
(2)sql语句
资源评论
普通网友
- 粉丝: 1
- 资源: 101
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功