From the course: SQL Server 2008 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 your output

Sorting your output - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Sorting your output

So let's take the idea of filtering our data a bit further. In this very simple SQL statement I am retrieving all the product information from the Product table here, and I have got a lot of different things in different colors, with names and Product IDs and list prices. What I would like to do is go buy the cheapest to the most expensive. Well it's yet another SQL clause and we'll put it right at the end of the SQL statement, and I'll just put in Order By. Well, order by what? Well, in this case I'd like to Order By ListPrice. I hit F5 to execute that and we are going with the ordered ListPrice. By default it will be ascending. If we want to make it descending we just type-in the word DESC afterwards, hit Execute and now we have by ListPrice descending. You can if you want to pick multiple columns to order on, so I could order for example by Color, ListPrice, and what this would do is order by color ascending and then ListPrice descending within it. So if I execute that we have…

Contents