SELECT TOP Clause IN SQL
The SELECT TOP clause is used to specify the number of records to return.
The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.
Note :- Not all database systems support the SELECT TOP clause.
Syntax :-
Example :- We create the following a table named is tblStudentRecord and inserts some records as shown below:-
Now, we use TOP Clause shown as below:-
We get only five top records from tblStudentRecord table.
Out put :-
The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.
Note :- Not all database systems support the SELECT TOP clause.
Syntax :-
SELECT TOP number|percent column_name(s) FROM table_name
Example :- We create the following a table named is tblStudentRecord and inserts some records as shown below:-
CREATE TABLE tblStudentRecord ( Name varchar(100), Rollno int primary key, Branch varchar(30),Email varchar(100),Address varchar(200) ) Insert some records :- INSERT INTO tblStudentRecord VALUES('Santosh kumar singh',1001,'Information Technology','sa@gmail.com','A-3033') INSERT INTO tblStudentRecord VALUES('Er. Reena Tanti',1002,'ECE','err@gmail.com','T-387, Gaya') INSERT INTO tblStudentRecord VALUES('Chandan kumar',1003,'CSE','chn@gmail.com','Gaya') INSERT INTO tblStudentRecord VALUES('Nand kishor kumar',1004,'BCA','nk@gmail.com','A-3033,Darbhanga') INSERT INTO tblStudentRecord VALUES('Abhinav kumar',1005,'MCA','ab@gmail.com','H-837') INSERT INTO tblStudentRecord VALUES('Santosh kumar singh',1006,'CSE','santosh@gmail.com','A-3031') INSERT INTO tblStudentRecord VALUES('Neha sharma',1007,'MCA','h@gmail.com','D-34,Patna') INSERT INTO tblStudentRecord VALUES('Pooja',1008,'ECE','pr@gmail.com','A-90, Jaipur, Rajashthan') INSERT INTO tblStudentRecord VALUES('Jaya Laxmi',1009,'CSE','jl@gmail.com','Kerla') INSERT INTO tblStudentRecord VALUES('Pakaj Kumar',1010,'BCA','pk@gmail.com','A-30,Darbhanga,Bihar') INSERT INTO tblStudentRecord VALUES('Abhinav kumar',1011,'ME','ab1@gmail.com','K-837')
Now, we use TOP Clause shown as below:-
select top(5)* from tblStudentRecord
We get only five top records from tblStudentRecord table.
Out put :-