- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Usage and syntax of INNER and OUTER JOIN in DB2
Problem: How to explain INNER JOIN and OUTER JOIN with the help of an example on ORDERS and TRANSACTION DB2 table.
Solution
The JOIN is used to combine data from one or more tables in DB2. There are two main types of JOIN — INNER JOIN and OUTER JOIN. The basic difference between them is, INNER JOIN is an intersection of two or more tables while outer join is union of two or more tables. Basically, INNER JOIN is used to combine the data from multiple tables using equal column value and on the other hand, in case of OUTER JOIN, if the column values are not equal then also the row will b e displayed with NULL values.
For example, consider the table below.
ORDERS
ORDER_ID | ORDER_DATE | TRANSACTION_ID |
A11243 | 10-08-2020 | Z67899 |
A22178 | 11-08-2020 | Z67009 |
TRANSACTIONS
TRANSACTION_ID | TRANSACTION_DATE |
Z67899 | 11-08-2020 |
Z67674 | 07-08-2020 |
For INNER JOIN, we will use the below query.
Example
SELECT ORDER_ID, TRANSACTION_ID FROM ORDERS FULL OUTER JOIN TRANSACTIONS ON ORDERS.TRANSACTION_ID = TRANSACTIONS.TRANSACTION_ID
ORDER_ID | TRANSACTION_ID |
A11243 | Z67899 |
For OUTER JOIN, we will use the below query.
Example
SELECT ORDER_ID, TRANSACTION_ID FROM ORDERS FULL OUTER JOIN TRANSACTIONS ON ORDERS.TRANSACTION_ID = TRANSACTIONS.TRANSACTION_ID
ORDER_ID | TRANSACTION_ID |
A11243 | Z67899 |
A22178 | NULL |
NULL | Z67674 |
- Related Articles
- Difference Between Inner Join and Outer Join in SQL
- Difference between Inner and Outer join in SQL
- How to do an inner join and outer join of two data frames in R?
- INNER JOIN vs FULL OUTER JOIN vs LEFT JOIN vs RIGHT JOIN in PostgreSQL?
- What are the limitations of using OUTER JOIN on a DB2 table?
- Example and usage of JOINS in DB2
- What is the use and syntax of SEQUENCE in DB2?
- Purpose and usage of SAVEPOINT in COBOL-DB2 program
- Purpose and usage of ROW-ID and SEQUENCE in a DB2
- Difference Between Left, Right and Full Outer Join
- How can we distinguish between MySQL CROSS JOIN and INNER JOIN?
- Which are Outer and Inner planets in our Solar System?
- Usage and example of Multi-index and Index-only access path in DB2
- What is the definition and usage of alternate key in a DB2 table?
- What is the usage and purpose of DCLGEN and host variables used in COBOL-DB2 program

Advertisements