sqlcmd.net validated sql reference
intermediate joining MySQL MariaDB SQL Server PostgreSQL SQLite

Join Tables With INNER JOIN

Combine rows from two tables when matching keys exist in both tables.

Docker-validated Not currently validation-green

Match employees to departments

Only rows with a matching department are returned. ORDER BY e.id keeps the example stable for validation.

Rows loaded before the example query runs.
Setup
CREATE TABLE departments (id INT, name VARCHAR(50));

CREATE TABLE employees (id INT, name VARCHAR(50), department_id INT);

INSERT INTO
  departments (id, name)
VALUES
  (1, 'Engineering'),
  (2, 'Finance');

INSERT INTO
  employees (id, name, department_id)
VALUES
  (1, 'Ada', 1),
  (2, 'Grace', 1),
  (3, 'Linus', 2);
Shared across supported engines.
SQL
SELECT
  e.name,
  d.name AS department
FROM
  employees e
  INNER JOIN departments d ON e.department_id = d.id
ORDER BY
  e.id;
Returned rows for the shared example.
namedepartment
AdaEngineering
GraceEngineering
LinusFinance

The join output is identical across engines for this example.

Where this command helps.

  • combining normalized data from related tables
  • showing only records that have a valid match on both sides

What the command is doing.

INNER JOIN returns only rows with matches on both sides of the join condition. It is a core SQL pattern for combining related data into a single result.