Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 6: DB2 SQL Functions, Joins and Subqueries


INNER JOIN

What is a join

  • A SELECT statement can retrieve data from two or more tables by performing a JOIN operation.
  • A join collects data from tables that have one specific column in common and combines the result into one result data set.
  • The join condition is specified in the WHERE clause, or with the ON keyword in ANSI syntax.
  • Table aliases like E and D keep the query short and readable.

What is an inner join

  • An inner join returns only the rows where both tables have matching values in the join columns.
  • Rows with no matching partner in the other table are dropped from the result.
  • It is the default join type: writing JOIN alone means INNER JOIN.
  • Example:-
    -- Old style: join condition in the WHERE clause SELECT E.LASTNAME, D.DEPTNAME FROM EMPLOYEE E, DEPARTMENT D WHERE E.WORKDEPT = D.DEPTNO; -- ANSI style: INNER JOIN with ON SELECT E.LASTNAME, D.DEPTNAME FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON E.WORKDEPT = D.DEPTNO;





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant