SQL SELECT TOP Clause || SELECT TOP Statement in SQL
Tutorial in Hindi:
- The SELECT TOP clause is used to indicate the quantity of records to return.
- The SELECT TOP clause is helpful on large tables with huge number of records. Returning a large number of records can affect execution.
- The SQL SELECT TOP clause is utilized to recover records from at least one tables in a data set and cutoff the quantity of records returned based on a fixed value.
SYNTAX:
Without condition show only top records from the table.
SELECT TOP number Column_name
FROM Table_name;
Show top records from the table with specified condition.
SELECT TOP number Column_name
FROM Table_name
WHERE Condition;
Show only Bottom records from the table by using ORDER BY keyword.
SELECT TOP number Column_name
FROM Table_name
ORDER BY Column_name DESC;
EXAMPLE:
Without condition show only top records from the table.
SELECT TOP 3 * FROM Student_Table;
OR
SELECT TOP 3 Student_Name, Student_Address FROM Student_Table;
Show top records from the table with specified condition.
SELECT TOP 5 * FROM Student_Table
WHERE Student_ID>105
OR
SELECT TOP 5 Student_ID, Student_Name FROM Student_Table
WHERE Student_ID>105
Show only Bottom records from the table by using ORDER BY keyword.
SELECT TOP 5 * FROM Student_Table
ORDER BY Student_ID DESC;
OR
SELECT TOP 5 Student_ID, Student_Name FROM Student_Table
WHERE Student_ID>105
ORDER BY Student_ID DESC;
0 Comments