Categories
SQL Server Step By Step

SQL Select Top Clause

SQL Select Top Clause

Hi friends, in this post we will learn about SQL Select Top Clause. Top clause is used to get TOP N number of records from table. Top clause can be very useful on tables with thousands of records. Fetching a large number of records can impact performance, so TOP clause is very handy in this case.

Earlier we had discussed about Like Clause SQL ServerSQL AND & OR OperatorsSQL Where Clause, Delete Query SQL Server, SQL Update Statement, SQL Select Statement, SQL Insert Statement, Drop Table SQL Server, Rename Table in SQL Server, Create Table SQL Server, Schema In SQL Server, SQL Server Operators, Data Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.

Table Structure:

ID NAME CLASS PERMADDRESS TEMPADDRESS
1 MANN XI AGRA NULL
2 JAI X MUMBAI NULL
3 AKSHAY IX GOA NULL
4 OM V DELHI NULL
5 AMAN VII GOA NULL
6 AMIT VII JAIPUR NULL

SQL Select TOP Clause Example:-

----SELECT DATABASE----
USE HIGHTECHNOLOGY
GO

----TOP CLAUSE EXAMPLES----

----SELECT TOP 3 RECORDS WITH ALL COLUMNS----
SELECT TOP 3 * FROM STUDENT_INFORMATION
GO

----SELECT TOP 3 RECORDS WITH SELECTED COLUMNS----
SELECT TOP 3 ID,NAME FROM STUDENT_INFORMATION
GO

SQL SELECT TOP CLAUSE