Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to rename a joined column during an inner join?

Say I have two tables, owner and dog. Both have column name, but I'd like to join them, so there is a problem since both tables have column name. Can I rename (alias) the name column in the dog table during the query?

like image 676
John Avatar asked May 13 '11 15:05

John


People also ask

How do I join two tables with different column names in SQL?

Merging tables by columns. Multiple tables can be merged by columns in SQL using joins. Joins merge two tables based on the specified columns (generally, the primary key of one table and a foreign key of the other).

Does inner join Change the table?

For inner joins, the order of the join operations does not affect the query (it can affect the ordering of the rows and columns, but the same data is returned). In this case, the result set is a subset of the Cartesian product of all the tables. The ordering doesn't matter.

How do I rename a column in SQL?

In Object Explorer, connect to an instance of Database Engine. In Object Explorer, right-click the table in which you want to rename columns and choose Rename. Type a new column name.

What happens when you inner join the same table?

A self join uses the inner join or left join clause. Because the query that uses the self join references the same table, the table alias is used to assign different names to the same table within the query.


1 Answers

select d.Name as DogName, o.Name from Dog d inner join Owner o on d.OwnerID = o.OwnerID 
like image 61
D'Arcy Rittich Avatar answered Oct 05 '22 21:10

D'Arcy Rittich