SELECT TOP clause:
- TOP clause is used to fetch specific
number of records from a table.
- This clause is very handy when we
have huge table of thousands of
record in it . And fetching data
from these tables are quite
time-consuming , in such situation
TOP clause can be used to fetch
limited number of records and saves
processing time.
- In MySQL we use LIMIT and
in Oracle we use ROWNUM clause in place of TOP clause.
Syntax for SQL Server:
SELECT TOP number|percent columnname(s)
FROM tablename;
Example:
SELECT TOP 5 * FROM Employee;
In the above query we are fetching top five employee records from Employee table.
Syntax for oracle:
SELECT columnname(s)
FROM tablename
WHERE ROWNUM <= number;
As we can see from the syntax ROWNUM is used in place of TOP clause for Oracle.
Example:
SELECT *
FROM Employee
WHERE ROWNUM <=3;
In the above example we are fetching top three employee records from Employee table.
Syntax for MySQL:
SELECT columnname(s)
FROM tablename
LIMIT number;
Example:
SELECT *
FROM Employee
WHERE LIMIT 5;
In the above query we are fetching top five employee records from Employee table.
0 Comment(s)