Home > Net >  How to alter the column names of a loaded table with SQL without altering the original database?
How to alter the column names of a loaded table with SQL without altering the original database?

Time:09-28

I'm crossing several tables of a PostgreSQL database and loading a new table (SELECT). Is there a way to change the column names of the new table without altering anything in the original database?

For example, how could I change the name of the column "col_3" to "new_column" in the following SQL query?

SELECT table1.col_1, table1.col_2, table2.col_3, table2.col_4, table2.col_5
FROM table1
INNER JOIN table2
ON table1.column_t_1= table2.column_t_2;

CodePudding user response:

 SELECT table1.col_1, table1.col_2, table2.col_3 as new_column_1, table2.col_4 as    new_column_2, table2.col_5 as  new_column_3
  FROM table1
  INNER JOIN table2
   ON table1.column_t_1= table2.column_t_2;

It is called "alias"

  • Related