Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRa Bha
2,201 PointsIf the tables are aliased to md and mk, how come the column names don't change when query is run?
I get that you can alias the table names to mk and md as in the example. But when I run the query
SELECT mk.MakeName, md.ModelName FROM make AS mk INNER JOIN model AS md ON mk.MakeID = md.MakeID;
I see that the output table still has column names MakeName and ModelName.
Why is this? And what then is the purpose of aliasing the table names as in the example?
1 Answer
cgeorge
5,493 PointsHello,
You may have already figured it out but you are giving the alias mk to the table name make.
SELECT - tells the database what columns to bring back. FROM- tells the database what table those columns belong to
so, FROM make AS mk is saying rename make table mk. If you want to give the column name an alias you need to use the AS keyword in the SELECT. SELECT mk.MakeName AS make, md.ModelName AS model FROM make AS mk INNER JOIN model AS md ON mk.MakeID = md.MakeID
I wouldn't give a column the same name as an alias though. It might get confusing.
I hope this helps. :)