From the course: Learning SQL Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Organize responses with ORDER BY - SQL Tutorial
From the course: Learning SQL Programming
Organize responses with ORDER BY
- [Instructor] When we get information back from a query, it can be in an order that isn't always helpful. So to sort data, we can use the ORDER BY keyword. Let's write a statement that will return a lot of rows. We'll get the first name and last name from every record in the people table. Looking at the result, it looks like it's all over the place in terms of sorting. This is the order that the records are stored in the database, sure, but that's not how I want to see them. So to change how they're sorted, I'll add an ORDER BY clause here at the end, and I need to give it a field with which to sort. Let's sort by first name for now. There we go. These first names are sorted alphabetically. These are sorted in an order called ascending which means that the lower the value, the earlier in the list it comes and the larger, the later it comes in the list. As we go through the list, the values ascend higher, or in this case later in the alphabet. Ascending order is the default which…
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)
Ask for data with SELECT4m 40s
-
(Locked)
Narrow down a query with WHERE4m 24s
-
(Locked)
Adding more criteria to a statement4m 17s
-
(Locked)
Broadening and limiting responses4m 11s
-
(Locked)
Organize responses with ORDER BY3m 2s
-
(Locked)
Find information about the data3m 47s
-
(Locked)
Solution: Retrieve data from the database1m 6s
-
(Locked)
-
-
-
-