Back to basics: Equi and non-equijoins

The join condition determines whether a join is an equijoin or a non-equijoin. An equijoin is a join with a join condition containing an equality operator. An equijoin combines rows that have equivalent values for the specified columns. When a join condition relates two tables by an operator other than equality, it is a non-equijoin. A query may contain equijoins as well as non-equijoins.

Equijoins are the most commonly used. An example of an equijoin:

SELECT e.first_name, d.department_name
  FROM employees e INNER JOIN departments d
       ON e.department_id = d.department_id
/
       
     FIRST_NAME              DEPARTMENT_NAME        
-------------------- ------------------------------ 
Steven               Executive                      
Neena                Executive                      
Lex                  Executive                      
Alexander            IT                             
Bruce                IT                             

Non-equijoins are less frequently used. An example of a non-equijoin:

SELECT zip_codes.zip_code, zones.ID AS zip_zone,
       zones.low_zip, zones.high_zip
  FROM zones INNER JOIN zip_codes
       ON zip_codes.zip_code BETWEEN zones.low_zip
                                 AND zones.high_zip
/

ZIP_CODE ZIP_ZONE LOW_ZIP HIGH_ZIP
-------- -------- ------- --------
57000    1        57000   57999 
84006    2        84000   84999 

Can you think of another non-equijoin example?


Possibly related:


Tagged , | Post a Comment