557 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
|A short blog listing many ways to create aliases for columns in SQL|
|It's not often that this owl learns new things about SQL when giving a course, but when I do, I like to share my new knowledge! This blog shows a new way to create aliases for columns in SQL.|
It's never too old to teach an old dog new tricks. Thanks to Chepren from a recent course for showing me this different approach to creating column aliases.
My colleague Andy Gould has already blogged about using column aliases. There are basically 3 ways, as shown in this query:
-- alias using quote marks
FilmName as 'Name of film',
-- if you don't have any spaces, you can
-- use the alias name without punctuation
FilmOscarWins as Oscars,
-- alternatively, you can use square brackets
FilmRunTimeMinutes as [Film Length]
This would give your 3 columns these names:
The output from the query above might look like this.
Note that you can omit the word AS from each line of the query above, although this owl thinks it's much clearer if you include it!
You can, however, also put the column alias at the start of each line of the SELECT statement:
-- the other way ...
'Name of film' = FilmName,
Oscars = FilmOscarWins,
[Film Length] = FilmRunTimeMinutes
Is this better? Probably not, but it's certainly different, and I was so stunned to discover it was possible that I thought I'd share it!
25 Aytoun Street