Search code examples
mysqlsqlddlcreate-table

Rename columns in SQL


I want to (directly) generate a table with the content from 2 columns of another table. How ca I change the names of the columns (rename them in the new table)?

Here´s an example:

CREATE TABLE X AS
SELECT
Table1.name,
Table1.act
FROM Y

->I don´t want to name the columns "name" and "act" as in the original table - I want to have "name" replaced by "customer" and "act" replaced by "status"


Solution

  • Do it like this:

    CREATE TABLE X AS
    SELECT
    Table1.name as customer,
    Table1.act as status
    FROM Y