Example 1
List products that have not been discontinued
Trackball appears in discontinued_products and is excluded. Keyboard and Mouse appear only in all_products and are returned. Use INTERSECT to find products that appear in both tables.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE all_products (id INT, name VARCHAR(50));
CREATE TABLE discontinued_products (id INT, name VARCHAR(50));
INSERT INTO
all_products (id, name)
VALUES
(1, 'Keyboard'),
(2, 'Mouse'),
(3, 'Trackball');
INSERT INTO
discontinued_products (id, name)
VALUES
(3, 'Trackball');Validated query Shared across supported engines.
SQL
SELECT
name
FROM
all_products
EXCEPT
SELECT
name
FROM
discontinued_products
ORDER BY
name;Expected result Returned rows for the shared example.
| name |
|---|
| Keyboard |
| Mouse |
Output is identical across all engines.