Cheat Sheets & Quick References

SQL JOIN Types Quick Reference

A compact explanation of common SQL JOIN types for querying related records in MySQL-backed PHP applications.

Overview

SQL joins combine rows from related tables. They are commonly used in PHP applications to retrieve articles with categories, orders with customers or records with related metadata.

Common JOIN types

  • INNER JOIN returns rows with matching records in both tables.
  • LEFT JOIN returns every row from the left table and matching rows from the right; unmatched right-side columns are NULL.
  • RIGHT JOIN returns every row from the right table and matching rows from the left.
  • CROSS JOIN returns combinations of rows from both tables.

Example

SELECT a.title, c.name AS category
FROM articles AS a
INNER JOIN categories AS c
    ON c.id = a.category_id;

Practical considerations

Join columns should have compatible types and suitable indexes. Be careful when joining one-to-many relationships because the result can contain multiple rows for a single parent record. Use explicit join conditions and qualify column names to avoid ambiguity.

Official resource

MySQL JOIN syntax: https://dev.mysql.com/doc/refman/8.0/en/join.html