Sorting Data

Now that you know how to get and limit the amount of rows returned in a result set to only the rows you need, let's talk a little about how to organize the data.

The ORDER BY Clause

The ORDER BY clause specifies the sort of a result set using one or more column names separated by commas. The sort is how the rows are organized; for instance, you can sort the result set in a query to the Products table so the ProductName column is listed in alphabetical order.

Note

Sort order cannot be used with SubQueries or to sort data of the type nText, Text, or image.

The sort can be both alphabetical and/or chronological. The following example returns all the rows in the Products table and orders them by the ProductName column in alphabetical ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.