Simple SQL Ordering Question
If I had the following relation
Staff (staffNo(PK), fName, lName, 开发者_如何学编程position, sex, DOB)
How would I go about writing a query which produced a list of all details of all female staff ordered by their second name then their first name?
My guess is:
SELECT * FROM Staff ORDER BY fName ASC, lName ASC WHERE sex = 'f'
Is this correct?
Well, you can try this out to see if this is correct :)
But you should swap where predicate with order by clause, and ordering predicates as well: if you want to sort by the last name at first - you should specify last name first in the order by.
SELECT * FROM staff WHERE sex = 'F' ORDER BY lName ASC, fName ASC
You had fName and lName the wrong way round, and your ORDER BY
comes after the WHERE
Try this query:
SELECT * FROM Staff WHERE sex = 'f' order by lName, fName;
精彩评论