SQL Keywords

SQL JOINS

What are SQL JOINS?

SQL JOINS combine rows from two or more tables based on a related column or logical relationship.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL JOINS: PostgreSQL, MySQL (8.0+ supports FULL JOIN via workaround or union), SQL Server, Oracle, SQLite, Snowflake, MariaDB, Redshift

SQL JOINS Full Explanation

SQL JOINS are clauses in a SELECT statement that let you query data spread across multiple tables as if it were a single result set. They work by matching rows using an ON or USING condition (or implicitly in a CROSS JOIN). The most common join types are:INNER JOIN – returns only matching rows.LEFT (OUTER) JOIN – returns all rows from the left table plus matching rows from the right.RIGHT (OUTER) JOIN – the mirror of LEFT JOIN.FULL (OUTER) JOIN – returns matches plus non-matching rows from both tables.CROSS JOIN – Cartesian product of both tables (every combination).SELF JOIN – a table joined to itself using table aliases.Joins allow normalization of schemas, reduce data duplication, and enable complex analytics. Performance depends on indexes, join order, and optimizer choices. Watch for NULL handling, duplicate column names, and join conditions that unintentionally create Cartesian products.

SQL JOINS Syntax

SELECT column_list
FROM table1 [AS t1]
  {INNER | LEFT [OUTER] | RIGHT [OUTER] | FULL [OUTER] | CROSS} JOIN table2 [AS t2]
    ON t1.column = t2.column;

SQL JOINS Parameters

  • join_type (string) - INNER, LEFT, RIGHT, FULL, CROSS
  • left_table (identifier) - first table in the join
  • right_table (identifier) - second table in the join
  • join_condition (expression) - Boolean predicate stated after ON or USING

Example Queries Using SQL JOINS

-- 1. Inner join customers and orders
SELECT c.id, c.name, o.order_date
FROM customers AS c
INNER JOIN orders AS o ON c.id = o.customer_id;

-- 2. Left join products with optional reviews
SELECT p.id, p.title, r.rating
FROM products AS p
LEFT JOIN reviews AS r ON p.id = r.product_id;

-- 3. Self join employees for manager relationships
SELECT e.name AS employee, m.name AS manager
FROM employees AS e
LEFT JOIN employees AS m ON e.manager_id = m.id;

Expected Output Using SQL JOINS

  • Each query returns a result set that merges columns from both tables where the join condition evaluates to TRUE (or all rows from one side in outer joins)

Use Cases with SQL JOINS

  • Retrieve order details with customer info in one query
  • Show all products even if they have no reviews
  • Build hierarchical employee org charts
  • Compare current and previous month data using self joins
  • Replace expensive subqueries with more performant joins

Common Mistakes with SQL JOINS

  • Omitting the join condition and producing a Cartesian product
  • Confusing LEFT and RIGHT JOIN directionality
  • Forgetting to qualify column names when they exist in both tables, causing ambiguous column errors
  • Expecting NULL-safe equality (use IS NULL checks when needed)
  • Using FULL JOIN where the database does not support it (e.g., MySQL pre-8.0)

Related Topics

SELECT, WHERE, GROUP BY, UNION, ON clause, USING clause, subqueries

First Introduced In

ANSI SQL-86 (X3.135-1986)

Frequently Asked Questions

What is the difference between INNER JOIN and LEFT JOIN?

INNER JOIN returns only matching rows; LEFT JOIN returns all rows from the left table plus matches from the right, filling non-matches with NULLs.

How do I join more than two tables?

Chain multiple JOIN clauses: SELECT ... FROM a JOIN b ON ... JOIN c ON ...; each additional JOIN adds one table to the result set.

Are joins slower than subqueries?

Not necessarily. With proper indexes, joins often outperform correlated subqueries because the optimizer can choose efficient join algorithms.

Can I join a table to itself?

Yes. Use table aliases to distinguish the two logical instances, enabling self joins for hierarchical or comparative analyses.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!