Use of SELECT TOP Statement in SQL

Use of SELECT TOP Statement in SQL:

(1) “SELECT TOP” statement is used to get a specific number of records.

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

SELECT TOP number column1, column2, …
FROM table_name;

(3) Let’s take an example to get specify records from the Vendor table as shown.

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

Select the database in SQL server and click on the New Query

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

SQL new query editor open

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

select top query for sql

Source Code:

–// Without “TOP” statement in Vendor table
Select [No_],[Name],[Address],[Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
–// Without “TOP” statement in Vendor table
–// With “TOP” statement in Vendor table
Select Top 5 [No_],[Name],[Address],[Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
–// With “TOP” statement in Vendor table

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

execute select top query for sql

(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.


Use of CREATE DATABASE Statement in SQL
How to Design Tiles view in Pages in Business Central
Create Export to Excel Report in Business Central
Usage of Keys in Business Central
Page Extension Object– Microsoft Docs

Leave a Reply