I have a problem that ORDER BY
is not working the way I want.
My code:
SELECT
LastName + ' ' + FirstName AS [Full name],
TitleOfCourtesy AS titleOfCourtesy,
CASE
WHEN TitleOfCourtesy IN ('Ms.', 'Mrs.')
THEN 'Female'
WHEN TitleOfCourtesy = 'Mr.'
THEN 'Male'
END AS Sex
FROM
Employees
WHERE
TitleOfCourtesy IN ('Mrs.','Ms.','Mr.')
-- ORDER BY Sex DESC;
This code returns this result set:
When I add ORDER BY(uncomment last line)
, it returns:
I think result should be like this (this is what I want):
Here is my Employees
table:
I don't understand why Callahan Laura
and Dodsworth Anne
is moving up in img 2. What happened? Did I misunderstand how ORDER BY
works? Any help is appreciated!