SQL ORDER BY Statement

SQL ORDER BY Statement:

(1) “ORDER BY” statement used for sorting records in the table from the database.

(2) Syntax of “ORDER BY” statement is:

SELECT DISTINCT column1, column2, …
FROM table_name
ORDER BY Col1, Col2….;

(3) Let’s take an example to sort records according to the “Address” column in the “Vendor table”.

(4) Select the database in the SQL server and click on the “New Query” button as shown.

select database for selecting records in sql

(5) After that new query editor open as shown.

new query editor open in sql

(6) After doing the above steps, write the query in the editor, as shown.

SQL ORDER BY Statement Example

Source Code:

–// Without “ORDER BY” condition in “Address” column in Vendor table
Select [No_],[Name],[Address] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
–// Without “ORDER BY” condition in “Country_Region Code” column in Vendor table

–// With “ORDER BY” condition in “Address” column in Vendor table
Select [No_],[Name],[Address]from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
Order By [Address]
–// With “ORDER BY” condition in “Country_Region Code” column in Vendor table

(7) After writing the query, then execute the query (Shortcut keys is F5) as shown.

execute the sql query for order by statement

(8) After executing the two queries in the same editor, SQL gives two results. Note: Recommended write and execute query one by one for reporting.


How to Create Sales and Receivables Setup in D365 BC
How to Create Purchases and Payables Setup in D365 BC

How to Calculate the Current Fiscal Year
How to Fix 24 Hours or Military Time in BC D365
Format Property– Microsoft Docs

Leave a Reply