Answers to Exercises: Sort Your Query Results

Question 1

Write a statement to select Employee NationalIDNumber, MaritalStatus, BirthDate and JobTitle, sorted by BirthDate.

SELECT   NationalIDNumber, 
         MaritalStatus, 
         BirthDate, 
         JobTitle
FROM     HumanResources.Employee
ORDER BY BirthDate

Question 2

Write a statement to select Person first and last names ordered by the upper case equivalent of their last name.   Remember:  We discussed UPPER in the previous lesson.

SELECT   FirstName,
         LastName
FROM     Person.Person
ORDER BY Upper(LastName)

Question 3

Select the first two names to appear in a sort of Person LastNames.

SELECT   TOP 2 FirstName,
         LastName
FROM     Person.Person
ORDER BY LastName

Question 4

Select the last three names to appear in a sort of Person LastNames.

 SELECT  TOP 3 FirstName,
         LastName
FROM     Person.Person
ORDER BY LastName DESC