Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
🗃 DB2

DB2 JOIN Operations

Intermediate 🕑 15 min read 👁 0 views

15

Code Example


## DB2 JOIN Operations

JOINs combine data from multiple tables based on related columns.

### JOIN Types

| Type | Description |
|------|-------------|
| INNER JOIN | Matching rows only |
| LEFT OUTER JOIN | All left + matching right |
| RIGHT OUTER JOIN | All right + matching left |
| FULL OUTER JOIN | All from both tables |

### INNER JOIN
Returns only rows with matches in both tables.

### LEFT OUTER JOIN
Returns all rows from left table, nulls for non-matches.

### Syntax Styles
\`\`\`sql
-- Explicit JOIN
SELECT ... FROM A INNER JOIN B ON A.key = B.key

-- Implicit JOIN (old style)
SELECT ... FROM A, B WHERE A.key = B.key
\`\`\`

### Self JOIN
Join a table to itself:
\`\`\`sql
SELECT E.NAME, M.NAME AS MANAGER
FROM EMP E, EMP M
WHERE E.MGR_ID = M.EMP_ID
\`\`\`

### Multiple JOINs
Chain multiple tables together.