Back-End Development SQL basics

SQL SELECT TOP

The SQL SELECT TOP clause is used to when one wishes to monitor the number of records that are returned in the result-set.
The SQL SELECT TOP defines the number of records to return.
The SQL SELECT TOP clause is very useful when dealing with large database or tables with large number of records.
Returning large records can impact performance

SQL server/ MS-Access syntax: (SQL SELECT TOP)

MySQL syntax: (SQL LIMIT)


Example:

SELECT * FROM customers LIMIT 5;

Oracle syntax: (SQL ROWNUM)


Example:
SELECT * FROM customers WHERE ROWNUM <= 5;

Consider this demo database:

A sample database-Customer table:
C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd
Example:


Result:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali