Today in a live learning session with a friend of mine Dumisani Ndubane, we found out a slight change in behavior when using ORDER BY to sort a result set with column alias by using the ``, '' or "" quote types.
'' and "" aren't affect by the sorting, only `` works but all quotes are allowed to do column aliasing. See queries below;
- This sort the Full name in ascending order (using `` quotes on column alias):
SELECT
CONCAT_WS(', ', lastName, firstname) `Full name`
FROM
employees
ORDER BY
`Full name`;
- This doesn't sort the result set. Note we used '' quotes
SELECT
CONCAT_WS(', ', lastName, firstname) 'Full name'
FROM
employees
ORDER BY
'Full name';
- This doesn't sort the result set. Note we used "" quotes
SELECT
CONCAT_WS(', ', lastName, firstname) "Full name"
FROM
employees
ORDER BY
"Full name";
Also, we where using MySQL version mysql Ver 8.0.19 for osx10.13 on x86_64 (Homebrew)
on Mac. Is this intentional, is there an explanation to this behavior? Also, why not stick with backticks(``) with MySQL identifiers and '' or "" for string literals. Why mix them?
I think this could be a user experience (UX) improvement for MySQL because the current status quo seems confusing for a newbie trying to learn.
What do the SO community think and thanks for your help in advance.