[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>一、定义
* 连接 Join:连接一般定义为 R ∞ S A θ B \underset{A \theta B}{R \infty S} AθBR∞S,其中
∞ \infty∞ 表示连接运算符, θ \theta θ 为比较运算符, A θ B A\theta B AθB 是条件表达式。含义是从 R R R 和
S SS 的笛卡尔积 R × S R \times S R×S 中选取 R R R 关系在 A A A 属性组上的值与 S S S 关系在 B B B
属性组上的值满足比较关系 θ θ θ 的元组。
* 等值连接 Equijoin:比较运算符 θ \theta θ 为 = = = 的连接运算称为等值连接,它是从关系 R R R 与 S S S
的广义笛卡尔积中选取 A A A、 B B B 属性值相等的那些元组。
* 自然连接 Natural Join:自然连接是一种特殊的等值连接。它要求两个关系中进行比较的分量必须是同名的属性组,并在结果中把重复的属性列去掉。
* 外连接 Outer Join:如果把舍弃的元组也保存在结果关系中,而在其他属性上填空值,这种连接就叫做外连接。
* 左外连接 Left Outer Join 或 Left Join:如果只把左边关系 R R R 中要舍弃的元组保留就叫做左外连接。
* 右外连接 Right Outer Join 或 Right Join:如果只把右边关系 S S S 中要舍弃的元组保留就叫做右外连接。
* 交叉连接 Cross Join:交叉连接返回被连接的两个表所有数据行的笛卡尔积
,返回的数据行数等于第一个表中符合查询条件的数据行数乘以第二个表中符合查询条件的数据行数。
交叉连接得到的是两张表数据的乘积,所以以下两种写法是等价的:
SELECT * FROM XS, KC; SELECT * FROM XS CROSS JOIN KC;
<>二、示例
关系R:
ABC
a1b15
a1b26
a2b38
a2b412
关系S:
BE
b13
b27
b310
b32
b52
R与S的等值连接:
AR.BCS.BE
a1b15b13
a1b26b27
a2b38b310
a2b38b32
R与S的自然连接:
ABCE
a1b153
a1b267
a2b3810
a2b3182
R与S的外连接:
ABCE
a1b153
a1b267
a2b3810
a2b382
a2b412NULL
NULLb5NULL2
R与S的左外连接:
ABCE
a1b153
a1b267
a2b3810
a2b382
a2b412NULL
R与S的右外连接:
ABCE
a1b153
a1b267
a2b3810
a2b382
NULLb5NULL2