Example 1
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.
CREATE TABLE orders (id INT, status_code VARCHAR(10));
INSERT INTO
orders
VALUES
(1, 'COMP'),
(2, 'PEND'),
(3, 'CANC'),
(4, 'COMP');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;| id | label |
|---|---|
| 1 | Completed |
| 2 | Pending |
| 3 | Cancelled |
| 4 | Completed |
CREATE TABLE orders (id INT, status_code VARCHAR(10));
INSERT INTO
orders
VALUES
(1, 'COMP'),
(2, 'PEND'),
(3, 'CANC'),
(4, 'COMP');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;| id | label |
|---|---|
| 1 | Completed |
| 2 | Pending |
| 3 | Cancelled |
| 4 | Completed |
MySQL uses `VALUES ROW(...)` syntax. All other engines use bare `VALUES (...)` parentheses. The query logic is identical across engines.