Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select all columns from 2 tables having duplicated columns

Tags:

sql

firebird

I have 2 tables Customer and Customer_address connected by a customer_code column.

I need to create a select query to bring all columns from both tables. The problem is that I need to use aliases for the duplicated columns.

I tried:

select * from Customer left join Customer_address on Customer.customer_code=Customer_address.customer_code

Not working as expected. How can I avoid the duplicated without having to type all columns ?

like image 611
Jonathan Livingston Seagull Avatar asked Sep 01 '25 16:09

Jonathan Livingston Seagull


1 Answers

If the only duplicate column name is the one used for the JOIN, you can use the USING clause:

select *
from Customer c left join
     Customer_address ca
     using (customer_code);
like image 150
Gordon Linoff Avatar answered Sep 04 '25 15:09

Gordon Linoff