📅  最后修改于: 2020-12-12 02:57:07             🧑  作者: Mango
且仅当满足给定的连接条件时,Join操作才会组合来自不同关系的相关元组。用⋈表示。
雇员
EMP_CODE | EMP_NAME |
---|---|
101 | Stephan |
102 | Jack |
103 | Harry |
薪水
EMP_CODE | SALARY |
---|---|
101 | 50000 |
102 | 30000 |
103 | 25000 |
Operation: (EMPLOYEE ⋈ SALARY)
结果:
EMP_CODE | EMP_NAME | SALARY |
---|---|---|
101 | Stephan | 50000 |
102 | Jack | 30000 |
103 | Harry | 25000 |
示例:让我们使用上面的EMPLOYEE表和SALARY表:
输入:
∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
输出:
EMP_NAME | SALARY |
---|---|
Stephan | 50000 |
Jack | 30000 |
Harry | 25000 |
外部联接操作是联接操作的扩展。它用于处理丢失的信息。
例:
雇员
EMP_NAME | STREET | CITY |
---|---|---|
Ram | Civil line | Mumbai |
Shyam | Park street | Kolkata |
Ravi | M.G. Street | Delhi |
Hari | Nehru nagar | Hyderabad |
FACT_WORKERS
EMP_NAME | BRANCH | SALARY |
---|---|---|
Ram | Infosys | 10000 |
Shyam | Wipro | 20000 |
Kuber | HCL | 30000 |
Hari | TCS | 50000 |
输入:
(EMPLOYEE ⋈ FACT_WORKERS)
输出:
EMP_NAME | STREET | CITY | BRANCH | SALARY |
---|---|---|---|---|
Ram | Civil line | Mumbai | Infosys | 10000 |
Shyam | Park street | Kolkata | Wipro | 20000 |
Hari | Nehru nagar | Hyderabad | TCS | 50000 |
外部联接基本上分为三种类型:
示例:使用上面的EMPLOYEE表和FACT_WORKERS表
输入:
EMPLOYEE ⟕ FACT_WORKERS
EMP_NAME | STREET | CITY | BRANCH | SALARY |
---|---|---|---|---|
Ram | Civil line | Mumbai | Infosys | 10000 |
Shyam | Park street | Kolkata | Wipro | 20000 |
Hari | Nehru street | Hyderabad | TCS | 50000 |
Ravi | M.G. Street | Delhi | NULL | NULL |
示例:使用上面的EMPLOYEE表和FACT_WORKERS关系
输入:
EMPLOYEE ⟖ FACT_WORKERS
输出:
EMP_NAME | BRANCH | SALARY | STREET | CITY |
---|---|---|---|---|
Ram | Infosys | 10000 | Civil line | Mumbai |
Shyam | Wipro | 20000 | Park street | Kolkata |
Hari | TCS | 50000 | Nehru street | Hyderabad |
Kuber | HCL | 30000 | NULL | NULL |
示例:使用上面的EMPLOYEE表和FACT_WORKERS表
输入:
EMPLOYEE ⟗ FACT_WORKERS
输出:
EMP_NAME | STREET | CITY | BRANCH | SALARY |
---|---|---|---|---|
Ram | Civil line | Mumbai | Infosys | 10000 |
Shyam | Park street | Kolkata | Wipro | 20000 |
Hari | Nehru street | Hyderabad | TCS | 50000 |
Ravi | M.G. Street | Delhi | NULL | NULL |
Kuber | NULL | NULL | HCL | 30000 |
也称为内部联接。这是最常见的连接。它根据相等条件基于匹配的数据。的等连接使用运算符(=)。
例:
客户关系
CLASS_ID | NAME |
---|---|
1 | John |
2 | Harry |
3 | Jackson |
产品
PRODUCT_ID | CITY |
---|---|
1 | Delhi |
2 | Mumbai |
3 | Noida |
输入:
CUSTOMER ⋈ PRODUCT
输出:
CLASS_ID | NAME | PRODUCT_ID | CITY |
---|---|---|---|
1 | John | 1 | Delhi |
2 | Harry | 2 | Mumbai |
3 | Harry | 3 | Noida |