Tutorials

SQL SELECT


SQL SELECT TOP


SELECT TOP in sql returns the topmost data from the table. 

When using it, we also specify the number of rows that we would like to fetch from the top of the table.

 

This is really helpful when we are working on a table that has lots of rows. 

 

Syntax for SELECT TOP

SELECT TOP row_count * FROM table_name;

row_count is the number of rows that you would like to get from the top.

Example of SELECT TOP

 

For demonstration purpose we will use 'tih_Courses' table.

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
 

From the above table suppose we want to fetch top 2 rows. So our sql query would be:

SELECT TOP 2 * FROM tih_Courses;

On executing the above query successfully, we will get:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline

We get top 2 rows only.

 

Our table contained minimal data here.

But when data in table is huge say thousands or lakhs of rows and you want only few sample data for analysis purpose then you can apply this query.



Please Share this page
Views : 54
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!