Is it possible to rename a joined column during an inner join?
select d.Name as DogName, o.Name
from Dog d
inner join Owner o on d.OwnerID = o.OwnerID
Yes, you can, but then you must list out all of the fields instead of using select *
:
select o.*, d.*
from owner o
inner join (select dog_id, name as dog_name, breed, age, owner_id from dog) d
on o.owner_id = d.owner_id
It is possible and very simple, do your SQL normally and add a comma after the asterisk and use 'AS'.
Before:
SELECT * FROM owner
INNER JOIN dog
ON owner.id = dog.id
After:
SELECT *, dog.name AS dogName FROM owner
INNER JOIN dog
ON owner.id = dog.id