UNION ALL stacks result sets that have the same number of columns without removing duplicates.

Program

Play the script to choose a starting day and combine signups with purchases into one activity feed.

union_all_activity.sql
CREATE TABLE signups (event_day TEXT, user_name TEXT);
INSERT INTO signups VALUES ('2026-02-01', 'Ada'), ('2026-02-03', 'Lin');
CREATE TABLE purchases (event_day TEXT, user_name TEXT);
INSERT INTO purchases VALUES ('2026-02-02', 'Ada'), ('2026-02-04', 'Nia');
WITH params(min_day) AS (VALUES ()) SELECT event_day, user_name, 'signup' AS event_type FROM signups WHERE event_day >= (SELECT min_day FROM params) UNION ALL SELECT event_day, user_name, 'purchase' AS event_type FROM purchases WHERE event_day >= (SELECT min_day FROM params) ORDER BY event_day, user_name, event_type;
CREATE TABLE signups (event_day TEXT, user_name TEXT);
INSERT INTO signups VALUES ('2026-02-01', 'Ada'), ('2026-02-03', 'Lin');
CREATE TABLE purchases (event_day TEXT, user_name TEXT);
INSERT INTO purchases VALUES ('2026-02-02', 'Ada'), ('2026-02-04', 'Nia');
WITH params(min_day) AS (VALUES ()) SELECT event_day, user_name, 'signup' AS event_type FROM signups WHERE event_day >= (SELECT min_day FROM params) UNION ALL SELECT event_day, user_name, 'purchase' AS event_type FROM purchases WHERE event_day >= (SELECT min_day FROM params) ORDER BY event_day, user_name, event_type;
CREATE TABLE signups (event_day TEXT, user_name TEXT);
INSERT INTO signups VALUES ('2026-02-01', 'Ada'), ('2026-02-03', 'Lin');
CREATE TABLE purchases (event_day TEXT, user_name TEXT);
INSERT INTO purchases VALUES ('2026-02-02', 'Ada'), ('2026-02-04', 'Nia');
WITH params(min_day) AS (VALUES ()) SELECT event_day, user_name, 'signup' AS event_type FROM signups WHERE event_day >= (SELECT min_day FROM params) UNION ALL SELECT event_day, user_name, 'purchase' AS event_type FROM purchases WHERE event_day >= (SELECT min_day FROM params) ORDER BY event_day, user_name, event_type;
UNION ALL `UNION ALL` keeps every row from both inputs.
compatible columns Both sides return day, user, and event type in the same positions.
event label A literal label records which source table produced each row.