Semijoin

Some parts in the output code are omitted for clarity reasons.

Description

A semijoin returns rows that match an EXISTS subquery without duplicating rows from the left side of the predicate when multiple rows on the right side satisfy the criteria of the subquery. Semijoin transformation cannot be done if the subquery is on an OR branch of the WHERE clause. (Oracle SQL Language Reference Semijoin Subsection)

Sample Source Patterns

Order by clause added because the result order may vary between Oracle and Snowflake.

Check this section to set up the sample database.

Basic Semijoin case

Oracle

IN -> Oracle_01.sql
SELECT * FROM hr.departments 
   WHERE EXISTS 
   (SELECT * FROM hr.employees 
       WHERE departments.department_id = employees.department_id 
       AND employees.salary > 2500)
   ORDER BY department_name;

Snowflake

OUT -> Oracle_01.sql
SELECT * FROM
   hr.departments
   WHERE EXISTS
   (SELECT * FROM
         hr.employees
       WHERE departments.department_id = employees.department_id
       AND employees.salary > 2500)
   ORDER BY department_name;

As proved previously the semijoin in Oracle is functionally equivalent to Snowflake.

Known Issues

No issues were found.

No related EWIs.

Last updated