oracle的连接查询(内外连接)

-- 连接查询的分类

-- 1.内连接:又叫做等值连接。

-- 2.外连接:又叫做左连接、右连接、全连接。

 

现已 commodity_table 和 store 这两张表 做示例;

store 表中的外键是 community_number,与之相关联的是 commodity_table 表的主键 serial_number 。

 

例:-- 内连接(简写)

select a.name,b.store_name from commodity_table a,store b where a.serial_number=b.commodity_number;

 

-- 内连接(完整的写法)

select a.name,b.store_name form from commodity_table a inner join store b on a.serial_number=b.commodity_number;

 

-- 外连接-左连接(以左表为基准,关联右表,关联上的数据直接显示,

-- 未关联上的则显示左表记录,右表记录为空值

select * from commodity_table a left join store b on a.serial_number=b.commodity_number;

--外连接-左连接的另一种简写方法

select * from commodity_table a,store b where a.serial_number=b.commodity_number(+);

 

-- 外连接-右连接(以右表为基准,关联左表,关联上的数据直接显示,

-- 未关联上的则显示右表记录,左表记录为空值

select * from commodity_table a right join store b on a.serial_number=b.commodity_number;

--外连接-右连接的另一种简写方法

select * from commodity_table a,store b where a.serial_number(+)=b.commodity_number;

 

-- 外连接-全连接

select * from commodity_table a full join store b on a.serial_number=b.commodity_number

order by serial_number;

 

-- 等价于 左连接跟右连接的集合

select * from commodity_table a left join store b on a.serial_number=b.commodity_number

union

select * from commodity_table a right join store b on a.serial_number=b.commodity_number;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值