Archive

Category Archives for "Sorting"

In SQL query results are sorted using the ORDER BY clause.  This page is devoted to articles covering various aspects of sorting, such as how to get the top rows in a result, and ways to fetch results from the “middle” of a result.

If you’re new to SQL, I would recommend reading Getting Started With SQL Server: 2. Sort Your Query Results.

I would also recommend the following, once you have the basics mastered:

All the examples for this lesson are based on Microsoft SQL Server Management Studio and the sample databases AdventureWorks and WideWorldImporters.  You can get started using these free tools using my guide Getting Started Using SQL Server

2

What is the Difference between ORDER and GROUP BY?

Differences in Order By versus Group By

The GROUP and ORDER BY clauses are both used to organize data.  Learn which is used to sort the data, and which is used for counting and summing. All the examples for this lesson are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.  You can get started using these free tools using […]

Continue reading
8

Use SQL Server to Sort Alphanumeric Values

Sort Alphanumeric Values with SQL Server Recently a reader asked me how to sort an alpha numeric field in SQL in natural order.  Alphanumeric values are commonly found and don’t sort naturally using numeric methods. When we have a numeric fields we expect values to be sorted in ordinal order, for example: 1,2,5,7,10,11,15,20,21 However when […]

Continue reading
9

Getting Started With SQL Server: 2. Sort Your Query Results

In this lesson you are going to explore how to sort your query results by using SQL’s ORDER BY statement.  Using this phrase allows us to sort our result in ascending or descending order.  In addition you can limit your query to a specified number of results. The lesson’s objectives are to: learn how to sort on […]

Continue reading