DavidSzczesniak
1/26/2018 - 3:05 PM

Aliases

Essentially nicknames for columns, allowing shorter queries and other conveniences.

\!h Basic column aliases  
SELECT artist_name AS artists FROM artist; -- current_name AS new_name FROM table;

\!h More useful example:
SELECT CONCAT(artist_name, " recorded ", album_name) AS recording
FROM artist INNER JOIN album USING (artist_id)
ORDER BY recording; 
-- groups information from two different tables and aliases it
+-------------------------------------------------------------+
| recording                                                   |
+-------------------------------------------------------------+
| Kylie Minogue recorded Light Years                          |
| Miles Davis recorded In A Silent Way                        |
| Miles Davis recorded Live Around The World                  |
| New Order recorded Brotherhood                              |
| New Order recorded Power, Corruption & Lies                 |
| New Order recorded Retro - John McCready FAN                |
| New Order recorded Retro - Miranda Sawyer POP               |
| New Order recorded Retro - New Order / Bobby Gillespie LIVE |
| New Order recorded Substance (Disc 2)                       |
| New Order recorded Substance 1987 (Disc 1)                  |
| Nick Cave & The Bad Seeds recorded Let Love In              |
| The Rolling Stones recorded Exile On Main Street            |
| The Stone Roses recorded Second Coming                      |
+-------------------------------------------------------------+