Question: Lesson 2 6 : Column alias In addition to making aliases for tables, you can also make them for columns. This clears up confusion on
Lesson : Column alias
In addition to making aliases for tables, you can also make them for columns.
This clears up confusion on which column is which. In the previous exercise, both columns in the result are simply called "name", and that can be confusing.
If you want to use an alias for a column, you add AS after the column name.
If we wanted to use left joins between character names and TV shows and clearly denote which column has character names, and which has TV show names, it would look like this:
SELECT
character.name AS character, tvshow. name AS name
FROM character
LEFT JOIN charactertvshow
ON
character.id charactertvshow.characterid
LEFT JOIN tvshow
ON charactertvshow.tvshowid tvshow.id;
Can you use left joins to match character names with the actors that play them, and use aliases to call the two columns returned character and actor?
Current tables:
character
tableidnameDoogie HowserBarney StinsonLily AldrinWillow RosenbergSteve UrkelHomer Simpson
tvshow
tableidnameBuffy the Vampire SlayerHow I Met Your MotherDoogie Howser, MDFriends
Expected Result:
tablecharacteractorDoogie Howser,Neil Patrick HarrisBarney Stinson,Neil Patrick HarrisLily Aldrin,Alyson HanniganWillow Rosenberg,Alyson HanniganSteve Urkel,nullHomer Simpson,null
charactertvshow
tableidcharacteridtvshowid
actor
tableidnameAlyson HanniganNeil Patrick HarrisAdam SandlerSteve Carell
characteractor
tableidcharacteridactorid
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
