Skip to content Skip to sidebar Skip to footer

CREATE TABLE ... AS SELECT With Discrete Values With Explicit Column Names

I want to execute this statement CREATE TABLE Tab2 AS SELECT 1, 'abc', 123456789.12 UNION SELECT 2, 'def', 25090003; on an SQL database. However column names of the resulting tabl

Solution 1:

Simply give the selected columns alias names as desired:

CREATE TABLE Tab2 AS SELECT 1 AS COLUMN1, \"abc\" AS COLUMN2, 123456789.12 AS COLUMN3 UNION SELECT 2, \"def\", 25090003;

Solution 2:

You can use the as clause for columns:

CREATE TABLE Tab2 AS
    SELECT 1           as col1,
    \"abc\"            as col2,
    :

Solution 3:

You should be able to give the columns in your SELECT aliases using the AS keyword:

CREATE TABLE Tab2 AS 
SELECT 1 AS col1, \"abc\" AS col2, 123456789.12 AS col3 
UNION SELECT 2, \"def\", 25090003;

Post a Comment for "CREATE TABLE ... AS SELECT With Discrete Values With Explicit Column Names"