SQL SELECT DISTINCT Statement

SQL SELECT DISTINCT Statement:

(1) “SELECT DISTINCT” statement used to select unique records in the table from the database.

(2) Syntax of “SELECT DISTINCT” statement is:

SELECT DISTINCT column1, column2, …
FROM table_name;

(3) Let’s take an example to select only distinct/unique values from the “Country_Region Code” 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 a query in the editor, as shown.

select distinct query in sql

Source Code:

–// For select all values in “Country_Region Code” column in Vendor table
Select [Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
where [Country_Region Code] = ‘AT’
–// For select all values in State column in Vendor table

–// For select distinct or unique values in “Country_Region Code” column in
Vendor table
Select Distinct [Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
where [Country_Region Code] = ‘AT’
–// For selecting particular fields in table

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

execute the query for select distcinct 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.


Installation Steps For Business Central D365 On-premises
Connect Microsoft Dynamics 365 BC (D365 BC) On-premises To Visual Code Editor
Creation Of Table In Microsoft Dynamics 365 BC
Page Creation In Microsoft Dynamics 365 BC
Report Creation In Microsoft Dynamics 365 BC
Getting Started with AL– Microsoft Docs

Leave a Reply