Categories
programming

SQL joins

Cross join

Cartesian product:

SELECT *
FROM movies
CROSS JOIN directors;

Full outer join

Like inner join but with all remaining rows from both sides:

SELECT *
FROM movies
FULL OUTER JOIN directors
  ON directors.id = movies.director_id;

Inner join

Only rows where condition is true:

SELECT *
FROM movies
INNER JOIN directors
  ON directors.id = movies.director_id;

Left join

All records from “left” table plus rows from the “right” table that match join condition:

SELECT *
FROM movies
LEFT JOIN directors
  ON directors.id = movies.director_id;

Use WHERE to filter results.

Right join

Reverse left join:

SELECT *
FROM movies
RIGHT JOIN directors
  ON directors.id = movies.director_id;

Source: freeCodeCamp

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.