How to design conditions for ORDER BY clauses

The ORDER BY clause is used to sort resulting data in ascending or descending order. With dbForge Query Builder for SQL Server, you can create an ORDER BY clause in the SELECT statement based on columns or expressions.

To work with ORDER BY clauses, open the Tabbed Editor by clicking Show Tabbed Editor icon Show Tabbed Editor on the Query toolbar or Query menu.

The Order By tab of the Tabbed Editor displays the ORDER BY clause divided into three panes: Columns, Ordered By, and Expression.

To create an ORDER BY clause

1. In the Columns pane, select the column(s) based on which data will be ordered by and click Add the column icon Add Column. This will move columns to the Ordered By pane.

2. For multiple columns: In the Ordered By pane, use Move up icon Move Up and Move down icon Move Down to change the order of columns.

By default, data is sorted in descending order. To change the sorting order, click Sort Ascending.

To exclude the column from the list, select it and then click Remove the column icon Remove Column.

Order by the column

3. In the Expression field, enter the expression by which the data from the returned query will be sorted. Then, click Add expression icon Add Expression.

Add the expression to the ORDER BY clause

4. Switch to the Text view to preview the SQL statement.

Preview the Order By clause filtered by the column

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Query Builder for SQL Server.
Request a demo

Request a demo

If you consider employing the Query Builder for your business, request a demo to see it in action.
Ready to start using dbForge Query Builder for SQL Server?