Example 1
Show all customers including those with no orders
Carol has no matching row in orders, so her total is NULL. Alice and Bob match normally. ORDER BY c.id keeps the result deterministic.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE customers (id INT, name VARCHAR(50));
CREATE TABLE orders (id INT, customer_id INT, total INT);
INSERT INTO
customers (id, name)
VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Carol');
INSERT INTO
orders (id, customer_id, total)
VALUES
(1, 1, 99),
(2, 2, 149);Validated query Shared across supported engines.
SQL
SELECT
c.name,
o.total
FROM
customers c
LEFT JOIN orders o ON c.id = o.customer_id
ORDER BY
c.id;Expected result Returned rows for the shared example.
| name | total |
|---|---|
| Alice | 99 |
| Bob | 149 |
| Carol | NULL |
Output is identical across all engines.