Reputation: 1
I have two tables that have many same column names so I need to add the table name before the column names when I join the tables. Is there some way to get table name reference before the column name without need to type it before every column in select clause?
In this example there are many columns in both tables and many of them have same names so I need to write TABLE2. before every column in select. Is there easier way to add it?
SELECT TABLE1.column1, TABLE2.column2, TABLE2.column3, TABLE2.column4,...
FROM TABLE1, TABLE2
WHERE TABLE1.column1 = TABLE2.column1;
Upvotes: 0
Views: 339
Reputation: 168671
Use table aliases:
SELECT t1.column1,
t2.column2,
t2.column3,
t2.column4 --, ...
FROM TABLE1 t1
INNER JOIN TABLE2 t2
ON ( t1.column1 = t2.column1 );
(And use ANSI join syntax rather than the legacy Oracle comma join syntax as it makes the relationships much clearer)
Upvotes: 2