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 can I use PostgreSQL XOR to compare two values?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I parse XML data using PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I convert a string to lowercase in PostgreSQL?
- How do I store an array in a PostgreSQL database?
- How can I integrate PostgreSQL with Yii2?
- How can I extract the year from a PostgreSQL timestamp?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
See more codes...