amazon-redshiftHow can I use Amazon Redshift UNION to combine data from multiple tables?
Amazon Redshift UNION is a powerful SQL command used to combine data from multiple tables into a single result set. This command can be used to append the data from two tables, or to combine the data from multiple tables into one result set.
Example code
SELECT *
FROM table1
UNION
SELECT *
FROM table2
This code will select all columns from both table1 and table2, and combine the data into a single result set. The output of this query will be a table with all the data from both tables.
The code consists of two parts:
- The first part,
SELECT * FROM table1
, is a SQL query that selects all columns from table1. - The second part,
UNION SELECT * FROM table2
, is the UNION command that combines the results of the two queries into one result set.
For more information on using the UNION command in Amazon Redshift, please refer to the Amazon Redshift Documentation.
More of Amazon Redshift
- How do I create a schema in Amazon Redshift?
- How do I use regular expressions with Amazon Redshift?
- How do I set up Amazon RDS with read replicas?
- How do I use Amazon Redshift's UNLOAD command?
- How can I use Amazon Redshift Utils to optimize my database?
- How can I transfer data from Amazon Redshift to an Amazon S3 bucket?
- How can I calculate the serverless pricing for Amazon Redshift?
- How can I monitor Amazon RDS using Zabbix?
- How do I use the Amazon Redshift YEAR function?
See more codes...