From the course: Programming Foundations: Databases

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Sorting results

Sorting results

- [Instructor] When we're querying a database, it's often useful to get the results back in a particular order. Using correct data types can help us out here too. Let's take a look at the dishes in the Dishes table in alphabetical order by name. To do that I'll write Select, Star, from Dishes, Order by, Name and then I'll run that query. The Order by clause takes the name of the field we're going to sort by. In the results area, I can see that the records are sorted by name. Apple pie, artichokes, barbecued tofu skewers, caffe latte, and so on. This sequence from A to Z is called ascending and that's the default. It's represented by ASC and I can invert the sort order to descending by changing that to DESC. Sorting works with any data type that has a logical sort order. So we can sort numbers, like the prices of our dishes. Let's change the query here and run it again and now I can see that the results are sorted by…

Contents