表的连接操作
来源:互联网 发布:淘宝小二招聘条件 编辑:程序博客网 时间:2024/05/01 21:03
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
select * from authors--23条
select * from publishers--8条
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--左(外部)连接测试,返回23条记录
--##特别写法##
select au_fname,au_lname,authors.city,pub_name
from authors,publishers
where authors.city*=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
left join publishers on authors.city=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
left outer join publishers on authors.city=publishers.city
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--右(外部)连接测试,返回9条记录
--注意是返回9条记录,而不是8条,是因为左表authors中城市为Berkeley的有2条记录
--##特别写法##
select au_fname,au_lname,authors.city,pub_name
from authors,publishers
where authors.city=*publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
right join publishers on authors.city=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
right outer join publishers on authors.city=publishers.city
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--完全(外部)连接测试,返回30条=23+8-1记录
select au_fname,au_lname,authors.city,pub_name
from authors
full join publishers on authors.city=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
full outer join publishers on authors.city=publishers.city
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--内部连接,返回2条记录
--隐式内连接
select au_fname,au_lname,authors.city,pub_name
from authors,publishers
where authors.city=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
inner join publishers on authors.city=publishers.city
select au_fname,au_lname,authors.city,pub_name
from authors
join publishers on authors.city=publishers.city
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--交叉连接
--184条=23X8
select au_fname,au_lname,pub_name
from authors,publishers
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--自我连接
select * from authors order by city --23条
--将返回49条记录,
/*
其计算方法是:有重复的城市名称则个数求平方,
没有重复的直接累加.
1+2X2+6+5X5+2X2+1+2X2+4
*/
select A.au_id,A.au_fname,A.au_lname,A.city
from authors A,authors B
where A.city=B.city
order by A.city
--23条,distinct关键字的作用是:使select与from之间的字段合并起来看作唯一的字段,判断其是否重复
select distinct A.city, A.au_fname,A.au_lname
from authors A,authors B
where A.city=B.city
order by A.city
select distinct A.au_fname,A.au_lname,A.city
from authors A
where A.city=A.city
order by A.city
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
- 表的连接操作
- 基本表的连接操作
- 数据库 表的连接操作
- 【SQL】基本表的连接操作
- Hive的连接操作
- derby数据库的连接操作
- 顺序串的连接操作
- php连接mysql的操作
- jdbc的连接及操作
- 静态字符串的连接操作
- JDBC的连接和操作
- HBuilder连接git的操作
- 考试系统的基础维护--基本表的连接操作
- 数据的基本操作与数据库的多表连接
- 考试系统的基础维护--基本表的连接操作
- 【工作精华】 多表连接的 金额加减操作
- 【数据结构】两个单循环链表的连接操作
- Oracle数据库表的操作之外键连接
- 浅谈内存泄漏
- 钩子要点
- 计算器之父——冯·诺依曼
- 用UDP实现可靠文件传输
- INFO: Header and Library Requirement When Set/Get Socket Options at the IPPROTO_IP Level
- 表的连接操作
- 有关递归的若干例子收集
- Wap 购物网站使用说明
- Java疑惑点解析(二)
- 关于二叉树中的递归小结
- 常用sql语句收集
- iframe自动自适应高度
- 生日快乐,我对自己说!...(^_^)
- web组件的三种关联关系