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

Use an Inline Table of Constant Values

Supply a small set of constant rows directly inside a query using a `VALUES` derived table — no temporary table or CTE required.

Docker-validated Not currently validation-green

Map order status codes to display labels inline

The VALUES clause inside the JOIN produces an inline three-row table with columns code and label. Joining orders on status_code = m.code resolves each code to its display label without any reference table or temporary object. MySQL requires ROW(...) around each value tuple as of 8.0.19; other engines accept the values directly in parentheses. The column aliases (code, label) after the derived table alias assign names to the inline columns so they can be referenced in the ON clause and SELECT list.

MySQL
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, status_code VARCHAR(10));

INSERT INTO
  orders
VALUES
  (1, 'COMP'),
  (2, 'PEND'),
  (3, 'CANC'),
  (4, 'COMP');
SQL
SELECT
  o.id,
  m.label
FROM
  orders o
  JOIN (
    VALUES
      ROW ('COMP', 'Completed'),
      ROW ('PEND', 'Pending'),
      ROW ('CANC', 'Cancelled')
  ) AS m (code, label) ON o.status_code = m.code
ORDER BY
  o.id;
idlabel
1Completed
2Pending
3Cancelled
4Completed
MariaDB SQL Server PostgreSQL SQLite
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, status_code VARCHAR(10));

INSERT INTO
  orders
VALUES
  (1, 'COMP'),
  (2, 'PEND'),
  (3, 'CANC'),
  (4, 'COMP');
SQL
SELECT
  o.id,
  m.label
FROM
  orders o
  JOIN (
    VALUES
      ('COMP', 'Completed'),
      ('PEND', 'Pending'),
      ('CANC', 'Cancelled')
  ) AS m (code, label) ON o.status_code = m.code
ORDER BY
  o.id;
idlabel
1Completed
2Pending
3Cancelled
4Completed

MySQL uses `VALUES ROW(...)` syntax. All other engines use bare `VALUES (...)` parentheses. The query logic is identical across engines.

Where this command helps.

  • joining a status code column to an inline label mapping without a reference table
  • providing a small fixed dataset for a query without any DDL or temp tables

What the command is doing.

A VALUES clause can stand alone as a derived table, letting you embed a hardcoded dataset inside a query without creating any database objects. The syntax (VALUES (...), (...)) AS alias(col1, col2) produces a virtual table that can be joined, filtered, or selected from like any other table. Common uses include mapping codes to labels inline, providing a lookup list for a JOIN, or seeding a small test dataset without setup DDL. MySQL requires the ROW() constructor around each set of values (since 8.0.19); all other engines use bare parentheses. For portability across older MySQL versions, a CTE with UNION ALL achieves the same result.