UNION ALL
An operator that stacks the rows of two queries with the same columns into one result, keeping duplicates.
In more detail
Plain UNION does the same but removes duplicate rows, which costs extra work. The keep-everything form is also a handy way to build a small list of literal rows inside a query.
Examples
Attackers use UNION SELECT in SQL injection to append rows from other tables, such as user names and password hashes, to a page's normal results.The SQL course uses it to list the three order statuses before a cross join.SELECT 'paid' AS status UNION ALL SELECT 'pending'Related terms
- SELECT — The SQL statement that reads data: it names the columns you want in the answer and, with FROM, the tables they come from.
- SQL injection — An attack where untrusted input is joined into a database query so that part of it runs as SQL, letting an attacker read or change data.
- CROSS JOIN — A join with no pairing rule, which pairs every row of one table with every row of the other.
Taught in
- Detection as Code: Authoring & Testing Sigma Rules — Security Operations & Threat Hunting (SOC)
- Tracking Advanced Persistent Threats & Profiles — Security Operations & Threat Hunting (SOC)
- Simulation: Attacks In The Logs — CompTIA Security+ (SY0-801) Exam Prep
- Cross Joins And Cartesian Bugs — PostgreSQL, Indexing & Relational Data Modeling
- Aggregate Functions — PostgreSQL, Indexing & Relational Data Modeling
- Common Table Expressions — PostgreSQL, Indexing & Relational Data Modeling