SQL查询中的连接
来源:互联网 发布:淘宝里的限时抢购 编辑:程序博客网 时间:2024/04/29 18:13
以下是SQL中的常用连接查询的简单写法,采用SQL-Server示例数据库pubs和Northwind
以下是详细代码:
use pubs
--内连接
select titleauthor.au_id,au_lname,title_id from authors inner join
titleauthor on titleauthor.au_id=authors.au_id
--内连接 (另一种写法,和上例结果一样)
select titleauthor.au_id,au_lname,title_id from authors ,
titleauthor where titleauthor.au_id=authors.au_id
--左外连接,将取出左表中的所有记录,右表没有对应将以Null进行添充
select titleauthor.au_id,au_lname,title_id from authors left join
titleauthor on titleauthor.au_id=authors.au_id
--右外连接,将取出右表中的所有记录,左表没有对应将以Null进行添充
select titleauthor.au_id,au_lname,title_id from authors right join
titleauthor on titleauthor.au_id=authors.au_id
--自连接,就是自己连接自己,
--如下题:请选择员工编号,员工姓名,及员工直接上级的编号,姓名
--解决方法:因为员工上级也是公司的员工,也在本表出现,这就要采用连接,而数据出自同一张表
--故采用自连接,自连接主要是给一张表起两个别名,假想成两张表来做,一切OK,
--代码如下:
use northwind
select a.employeeid,a.lastname,a.reportsto,b.lastname from employees a
left join employees b on a.reportsto=b.employeeid
select employeeid,lastname,reportsto from employees
- SQL查询中的连接
- SQL查询中的连接
- SQL查询中的连接
- sql中的连接查询
- SQL中的连接查询
- SQL 中的连接查询
- SQL中的连接查询与嵌套查询
- sql中的3中连接查询
- 数据库SQL语言中的连接查询(一)
- SQL中的各种连接及查询
- SQL查询--连接查询
- MSTR如何通过实体实现SQL中的连接查询
- 查询SQL Server中的数据库连接用户名与连接密码
- 看一看关于在sql查询过程中的连接问题
- SQL扩展之T-SQL中的数据查询语言之连接查询
- Sql连接查询
- SQL连接查询
- SQL连接查询类型
- ADO.net打开connection连接
- 使用免费的flash播放器哈哈
- Spring AOP的功能和目标
- 熵的概述
- 数据提供程序中Command组件使用
- SQL查询中的连接
- .net中读Excel数据
- sql中的日期和時間處理
- .net fileupload上传控件【原创】
- 在VDSP中编译uclinux(7):令人困惑的成功
- 换种方式实现Ajax的异步传输
- 嵌入式小波零树(EZW)算法的过程详解和Matlab代码(2)编码过程(081227-补充quantifier程序)
- vb.net静态生成页面技术【原创】
- 用OpenInventor实现的NeHe OpenGL教程-第七课