• Teach Your Self With
             w3htmlschool.com

MYSQL Limit

When a query returns manyrows,but you want to see only a few of the ,add a LIMIT clause. This is an MYSQL -exclusive option that allows you to limit the output f a query to the first rows of the result set.

Syntax


SELECT DISTINCT
columns
FROM
table_name
WHERE
column OR column
LIMIT no
Table
+----------------+------------+
| Field | Type |
+----------------+------------+
| Code | char(3) |
| Name | char(52) |
| Continent | char(40) |
| Region | char(26) |
| SurfaceArea | float(10,2)|
| IndepYear | smallint(6)|
| Population | int(11) |
| LifeExpectancy | float(3,1) |
| GNP | float(10,2)|
| GNPOld | float(10,2)|
| LocalName | char(45) |
| GovernmentForm | char(45) |
| HeadOfState | char(60) |
| Capital | int(11) |
| Code2 | char(2) |
+----------------+------------+
Example
SELECT Name, Population FROM Country WHERE Population > 100000000 OR (Continent = 'Asia' ) LIMIT 5;
Output
mysql> SELECT Name, Population FROM Country WHERE Population > 100000000 OR (Continent = 'Asia' ) limit 5;
+----------------------+------------+
| Name | Population |
+----------------------+------------+
| Afghanistan | 22720000 |
| United Arab Emirates | 2441000 |
| Armenia | 3520000 |
| Azerbaijan | 7734000 |
| Bahrain | 617000 |
+----------------------+------------+
5 rows in set (0.69 sec)