Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
546 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers 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
Search our website
We also send out useful tips in a monthly email newsletter ...
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. |
In this blog
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:
SELECT
-- 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]
FROM
tblFilm
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:
SELECT
-- the other way ...
'Name of film' = FilmName,
Oscars = FilmOscarWins,
[Film Length] = FilmRunTimeMinutes
FROM
tblFilm
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!
Some other pages relevant to the above blog include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.