In this article, we will explain how we can get data from a different table with insert and what we should pay attention to between these tables.
Example:
1 | INSERT INTO Original_Table(columns) SELECT columns FROM Copy_desired_table |
The columns of the tables must be the same.
The data types of the columns of the tables must be the same.
In the PLPGSQL sentence above, the number of columns between the tables must be equal.
The part specified as Original_Table above is the column where the data is to be transferred.
The table to be copied is the table from which we will get the data.
First, we check our data by selecting both tables.
We listed the data in the personnel table above and we saw that there are 4 data in total.
There are 3 records in the table that we want to transfer to the personnel table.
We transfer them to the other table as follows
1 | INSERT INTO personnel(name,surname,department) SELECT name,surname,department FROM PERSONEL_OLD; |
We transferred the data to the Personnel table above with insert, let’s verify this by selecting the personnel table.