Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle given column names

I have 2 tables with 2 columns (user_id and year).

Query1:

SELECT * FROM table_1 t1 
FULL JOIN table_2 t2 ON t1.user_id=t2.user_id AND t1.year=t2.year

Produces following column names:

user_id, year, user_id_1, year_1

Query2:

CREATE TABLE table_copy AS SELECT * FROM
(SELECT * FROM table_1 t1 
 FULL JOIN table_2 t2 ON t1.user_id=t2.user_id  AND t1.year=t2.year);

Produces following vague column names:

QCSJ_C000000000400000, QCSJ_C000000000400002, QCSJ_C000000000400001, QCSJ_C000000000400003

Is there a short way to force Oracle query2 to use the same names as query1 without writing them explicitly (it is important when there are many columns)? Maybe some Oracle settings?

like image 410
reforrer Avatar asked Aug 20 '26 02:08

reforrer


1 Answers

List your columns and use AS to specify the column name.

e.g.

CREATE TABLE table_copy AS
SELECT t1.user_id AS t1_user_id,
       t1.year    AS t1_year,
       t2.user_id AS t2_user_id,
       t2.year    AS t2_year
FROM   table_1 t1
FULL   JOIN table_2 t2 ON t1.user_id=t2.user_id
AND    t1.year=t2.year;
like image 114
cagcowboy Avatar answered Aug 21 '26 15:08

cagcowboy