From the course: SQL Server 2014 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sorting results with ORDER BY - SQL Server Tutorial
From the course: SQL Server 2014 Essential Training
Sorting results with ORDER BY
- SQL SELECT statements also allow us to easily sort the results based on some field from smallest to largest. So I'll open up a new query and we'll start with the basic query we've been using. Go ahead and Execute that. I can actually sort the results by any of these columns. Probably the easiest to demonstrate is the numerical VacationHours column. So at the end of the SELECT statement I'm going to type in the keywords ORDER BY and there is a space between ORDER and BY. So I type in ORDER BY and now all I need to do is type in the name of the column that I would like to sort on. In this case, VacationHours. Now I'll Execute that. And now we see the first results that came up or some employees that have zero vacation hours. And we can scroll all the way down to the end of the result set and we see the people with the most vacation hours come up at the end. So the default sort behavior is to go from the smallest value to the largest value. If you would like to accomplish the opposite…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
What is SQL?3m 34s
-
(Locked)
Basic SELECT statement3m 35s
-
(Locked)
Filtering results with a WHERE clause3m 48s
-
(Locked)
Using wildcards in a WHERE clause2m 38s
-
(Locked)
Sorting results with ORDER BY4m 48s
-
(Locked)
INSERT statements4m 24s
-
(Locked)
UPDATE statements3m 12s
-
(Locked)
DELETE statements2m 42s
-
(Locked)
-
-
-
-
-
-
-
-
-