Press "Enter" to skip to content

mysql_limit

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 structure Used for Example explanation

+—————-+————+
| 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 for MYSQL Limit

SELECT Name, Population FROM Country WHERE Population > 100000000 OR (Continent = ‘Asia’ ) LIMIT 5;

Output of Above Example

+———————-+————+
| Name | Population |
+———————-+————+
| Afghanistan | 22720000 |
| United Arab Emirates | 2441000 |
| Armenia | 3520000 |
| Azerbaijan | 7734000 |
| Bahrain | 617000 |
+———————-+————+
5 rows in set (0.69 sec)