MySQL Tutorial
The SELECT statement is used to select or retrieve the data from tables.
The SELECT TOP clause is used to specify the number of records to return.
The top clause specifies that how many rows are returned.
If a table has a large number of data, select top statement determines that how many rows will be retrieved from the given table.
SELECT TOP number|percent column_name(s)
FROM table_name
WHERE [condition]
Here, number is the max numbers you want to retrieve.
Let's put these statements into real use.
We've a table named Students in our database that contains the following records:
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | C++ |
2 | SAM | Python |
3 | Sara | HTML | 4 | Rim | Java |
5 | Micheal | MySQL |
6 | Lara |
Now we will fetch the top 3 records from the Students table.
SELECT TOP 3 * FROM Students;
The above SELECT statement selects Top 3 columns from the Students table.
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | C++ |
2 | SAM | Python |
3 | Sara | HTML |