5 SQL JOINS Useful for DB2 projects

In interviews, you may get a question about Joins. Here are the frequently asked JOIN in DB2 questions.

JOINS in DB2

When you want to see information from multiple tables, you can use a SELECT statement. SELECT statements can retrieve and join column values from two or more tables into a single row. The retrieval is based on a specified condition, typically of matching column values.

DB2 for ZOS supports different kinds of joins. Those are:

The main ingredient of a join is, typically, matching column values in rows of each table that participates in the join. The result of a join associates rows from one table with rows from another table. Depending on the type of join operation, some rows might be formed that contain column values in one table that do not match column values in another table.

  • Inner join – Combines each row of the left table with each row of the right table, keeping only the rows in which the join condition is true.
  • Outer join – Includes the rows that are produced by the inner join, plus the missing rows, depending on the type of outer join
  • Left outer join Includes the rows from the left table that were missing from the inner join.
  • Right outer join Includes the rows from the right table that were missing from the inner join.
  • Full outer joinIncludes the rows from both tables that were missing from the inner join.

We can specify joins in the FROM clause of a query. Data from the rows that satisfy the search conditions are joined from all the tables to form the result table.

Interview Questions about Joins

In the case of Left outer join, there is no matching rows of joined tables?

  • Inner join
    You can use an inner join in a SELECT statement to retrieve only the rows that satisfy the join conditions on every specified table.
  • Left outer join
    The LEFT OUTER JOIN clause lists rows from the left table even if there are no matching rows on right table.
  • Right outer join
    The RIGHT OUTER JOIN clause lists rows from the right table even if there are no matching rows on left table.
  • Full outer join
    The FULL OUTER JOIN clause results in the inclusion of rows from two tables. If a value is missing when rows are joined, that value is null in the result table.

Best example for Joins. Reference IBM.

Recent Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.