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

Organize responses with ORDER BY - SQL Tutorial

From the course: Learning SQL Programming

Start my 1-month free trial

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…

Contents