没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
join 方式
(1) cross join
参与select语句所有表的的所有行的笛卡尔乘积
select au_lname ,title
from authors cross join titiles
outer join 对参与join的两个表有主从之分,处理方式以主表的每条数据去match 从属表的列,合乎条件的数据是我们所要的答案,不合乎条件的也是我们要的答案,只不过哪些从属表选取的列将被添上null。
(2) left join
左边的为主表,右边为从属表
select a.cust_id ,b.order_date,b.tot_ant
from customer a left join sales b
on (a.cust_id =b.cust_id and b.order_date>''1996/10/15'')
可以写为
select a.cust_id,b.order_date,b.tot_ant
from custom a
left join (select * from sales where order_date>''1996/10/15'') b
on a.cust_id =b.cust_id
(3) right join
左边的表为从属表,右边的表为主表
(4) self join
self join 常用在同一表内不同数据间对同一列的比较
select a.emp_no,a.emp_name,b.emp_no,b.emp_name,a.date_hired
from employee a
join employee b
on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
order by a.date_hired
这样会重复数据,只要加上一句 and a.emp_name>b.emp_name
(5) full join
不仅列出符合条件的数据,两边未符合join条件的数据也会一并列出。哪些未符合join条件的数据如果在select列中无法得到对应的值则填上null
select a.cust_id,b.tot_amt
(1) cross join
参与select语句所有表的的所有行的笛卡尔乘积
select au_lname ,title
from authors cross join titiles
outer join 对参与join的两个表有主从之分,处理方式以主表的每条数据去match 从属表的列,合乎条件的数据是我们所要的答案,不合乎条件的也是我们要的答案,只不过哪些从属表选取的列将被添上null。
(2) left join
左边的为主表,右边为从属表
select a.cust_id ,b.order_date,b.tot_ant
from customer a left join sales b
on (a.cust_id =b.cust_id and b.order_date>''1996/10/15'')
可以写为
select a.cust_id,b.order_date,b.tot_ant
from custom a
left join (select * from sales where order_date>''1996/10/15'') b
on a.cust_id =b.cust_id
(3) right join
左边的表为从属表,右边的表为主表
(4) self join
self join 常用在同一表内不同数据间对同一列的比较
select a.emp_no,a.emp_name,b.emp_no,b.emp_name,a.date_hired
from employee a
join employee b
on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
order by a.date_hired
这样会重复数据,只要加上一句 and a.emp_name>b.emp_name
(5) full join
不仅列出符合条件的数据,两边未符合join条件的数据也会一并列出。哪些未符合join条件的数据如果在select列中无法得到对应的值则填上null
select a.cust_id,b.tot_amt
资源评论
watchsea0001
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功