Site icon Database Tutorials

PostgreSQL UNION and UNION ALL

In today’s article, we will learn how to use PostgreSQL UNION operator to combine result sets of multiple queries into a single result sets.

Things to consider when using UNION and UNION ALL:

The same number of columns must be selected in the first table and the second table; if they are different, you will receive an error.

The data types of the columns to be written in UNION and UNION ALL must be the same.

The columns and data of the Müsteriler and Personel tables are as above.

First, let’s print the recurring data for sehir once.

In the example below, we use the UNION ALL command to display all records.

Exit mobile version