SQL SELECT distinct | SQL SELECT TOP, LIMIT, ROWNUM
The SQL SELECT distinct can be used to return the specified number of records, it is a very useful clause on a large table with thousands of record available in the table and all database systems support the SELECT TOP Clause.
SQL SELECT Distinct syntax

|
1 2 |
SELECT TOP n column-names FROM table-name |
|
1 2 3 |
SELECT TOP 5 Id, CustomerName, ProductPrice, Quantity FROM ProductSale ORDER BY UnitPrice DESC |
| ProductSale |
|---|
| Id |
| CustomerName |
| ProductPrice |
| Quantity |
Result: Finally 5 Records
Therefore Below is a selection from the “product sales” table:
Therefore Below is a selection from the “product sales” table:
| Id | CustomerName | ProductPrice | Quantity |
|---|---|---|---|
| 1 | Abhishek | 2500 | 70 |
| 22 | Devendra | 7500 | 30 |
| 12 | Sonu | 4500 | 90 |
| 32 | Yahim | 4100 | 80 |
| 172 | Zamin | 2900 | 110 |
SQL Server / MS Access Syntax
|
1 2 |
SELECT TOP number|percent column_name(s) FROM table_name; |
similarly, Equivalent in MySQL and Oracle
MySQL
|
1 2 3 |
SELECT column_name(s) FROM table_name LIMIT number; |
Oracle Syntax
|
1 2 3 |
SELECT column_name(s) FROM table_name WHERE ROWNUM <= number; |
PERCENT Example
|
1 |
SELECT TOP 50 PERCENT * FROM Customers; |
Resource
SQL