SQL SELECT TOP Clause
SQL SELECT TOP clause is used to retrieve top N records or by percentage value from specified table(s) and limits the records by mentioned value in the query. If you want to fetch records in a specific order then you can mention ORDER BY clause in conjunction with SELECT TOP clause otherwise you will get random TOP N records from table.
SELECT TOP <Number | Percent> ColumnName(s)
We will take few examples to understand SELECT TOP clause. We will use Student table and fetch top 10 records from the table as given below.
SELECT TOP 10 *FROM Student
Now we will select specific columns FirstName, LastName and Country from Student table.
SELECT TOP 10 FirstName, LastName, Country FROM Student
Here, we will see example for TOP N PERCENT of Student table as shown below.
SELECT TOP 8 PERCENT * FROM Student
Now we will use ORDER BY clause with TOP N records in Student table so that we can get sorted records.
SELECT TOP 10 FirstName, LastName, Country FROM Student ORDER BY LastName DESC
Reference: Manzoor Siddiqui [www.SQLServerLog.com]