postgresqlHow do I use PostgreSQL's UNION ALL statement?
The PostgreSQL UNION ALL statement is used to combine the result sets of two or more SELECT statements into a single result set. It does not remove duplicate rows from the result set, unlike the UNION statement.
Example code
SELECT * FROM table1
UNION ALL
SELECT * FROM table2;
The example code above will combine the results from both table1 and table2 into a single result set.
Code explanation
- SELECT: specifies the columns to be returned by the query
- FROM: specifies the table(s) from which to retrieve the data
- UNION ALL: combines the result sets of two or more SELECT statements into a single result set
Helpful links
More of Postgresql
- How do I use the PostgreSQL hash function?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL's XMIN and XMAX features?
- How do I set the PostgreSQL work_mem parameter?
See more codes...