The previous two topics built the mechanics. This topic puts them to work on the job set operators exist for in most companies: producing one unified report from several structurally similar sources — regions, years, systems, or teams that each maintain their own table.
Business data integration with set operators means: identify N tables (or filtered subsets of one table) that represent the same kind of business entity, align their columns, stack them with UNION ALL (almost always — this is a reporting/event context, not a deduplication one), and add a discriminator column identifying where each row came from.
Organizations rarely centralize data collection perfectly. Regional offices keep regional tables. Fiscal years get archived into yearly tables. Two departments track the “same” thing in two systems that were never designed to talk to each other. Reporting still needs one unified view — set operators are how that unified view gets built without redesigning the underlying systems.
A retail chain’s sales_us, sales_emea, and sales_apac tables share identical columns but live in different schemas because each region’s team owns their own reporting pipeline. Leadership wants one global sales dashboard. UNION ALL with a region discriminator column solves this in one query.
sales_us, sales_emea, sales_apac into one SELECT for an executive dashboard.subscriptions_legacy_billing and subscriptions_new_billing during a platform migration period when both systems are live simultaneously.employees_hq and employees_acquired_company into one unified headcount report after a merger. sales_us ──┐
sales_emea ──┼── UNION ALL ──► one unified "global_sales" result
sales_apac ──┘ (+ a literal 'region' column per branch)
SELECT column_list, 'us' AS region FROM sales_us
UNION ALL
SELECT column_list, 'emea' AS region FROM sales_emea
UNION ALL
SELECT column_list, 'apac' AS region FROM sales_apac;
The discriminator column — a literal string or code identifying the source branch — is what separates a merely-functional integration query from a production-quality one. Without it, once three sources are stacked into one result set, there is no way for a downstream consumer to trace a row back to its origin, which becomes critical the moment someone asks “wait, which region is driving this spike?”
SELECT emp_name, dept_name, 'HQ' AS source_system FROM employees_hq
UNION ALL
SELECT emp_name, dept_name, 'Acquired' AS source_system FROM employees_acquired;
-- Unified company directory: current employees and departments, one list,
-- duplicates preserved (an audit-facing report, not a dedup list)
SELECT emp_name AS directory_name, 'employee' AS entity_type FROM employees
UNION ALL
SELECT dept_name AS directory_name, 'department' AS entity_type FROM departments;
-- Cross-year revenue report
SELECT order_id, order_total, 2024 AS fiscal_year FROM orders_2024
UNION ALL
SELECT order_id, order_total, 2025 AS fiscal_year FROM orders_2025;
UNION ALL — integration reporting almost always needs every row preserved, since two branches by definition come from different sources and a “duplicate” is rarely a true duplicate.UNION ALL-based integration view is one of the most common places a CREATE VIEW earns its keep — it hides the integration complexity from every downstream analyst.amount vs. total_amount), aliasing to one canonical name in the integration layer is essential — this is where data contracts should be enforced.UNION ALL across N sources is roughly the cost of N independent queries plus a cheap concatenation — no deduplication sort is involved. If the integration view is queried frequently, consider materializing it (a materialized view, or a scheduled table load) rather than recomputing the multi-source union on every request.
| Feature | MySQL | PostgreSQL | SQL Server | Oracle |
|---|---|---|---|---|
Literal discriminator column ('us' AS region) |
✅ | ✅ | ✅ | ✅ |
Views over UNION ALL |
✅ | ✅ | ✅ | ✅ |
| Materialized views | via triggers/manual | ✅ native | Indexed Views | ✅ native |
UNION ALL for integration reporting; only deduplicate explicitly, and only when justified.UNION ALL logic into every report instead of centralizing it once.UNION instead of UNION ALL for integration reporting, silently merging two legitimately distinct rows from different sources that happen to look identical.UNION ALL, not UNION, the default choice when integrating regional or yearly report tables?UNION ALL of three regional tables. Walk through your diagnostic approach.Business data integration is where set operators earn their keep in day-to-day analytics: stacking structurally similar sources into one reportable view, almost always with UNION ALL, always with a discriminator column, and ideally centralized behind a single view or model.
UNION ALL query combining employees and a hypothetical contractors table into one all_personnel report with a worker_type discriminator column.dept_name for each person by joining to departments inside each branch before the UNION ALL.interns table were added next year with a differently-named ID column (intern_id instead of emp_id).UNION ALL and wildcard table patterns