Join

Adds columns from another table, matching rows based on a condition.

  1. join side:{inner|left|right|full} {table} {[conditions]}

Parameters

  • side decides which rows to include, defaulting to inner.
  • Table reference
  • List of conditions
    • The result of join operation is a cartesian (cross) product of rows from both tables, which is then filtered to match all of these conditions.
    • If name is the same from both tables, it can be expressed with only ==col.

Examples

PRQL

  1. from employees
  2. join side:left positions [employees.id==positions.employee_id]

SQL

  1. SELECT
  2. employees.*,
  3. positions.*
  4. FROM
  5. employees
  6. LEFT JOIN positions ON employees.id = positions.employee_id

PRQL

  1. from employees
  2. join side:left p=positions [employees.id==p.employee_id]

SQL

  1. SELECT
  2. employees.*,
  3. p.*
  4. FROM
  5. employees
  6. LEFT JOIN positions AS p ON employees.id = p.employee_id

Self equality operator

If the join conditions are of form left.x == right.x, we can use “self equality operator”:

PRQL

  1. from employees
  2. join positions [==emp_no]

SQL

  1. SELECT
  2. employees.*,
  3. positions.*
  4. FROM
  5. employees
  6. JOIN positions ON employees.emp_no = positions.emp_no