
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL LIMIT in a Range: Fail to Display First 3 Rows
Following is the syntax to display only the first 3 rows with LIMIT set in a range −
select *from yourTableName limit yourStartIndex,yourEndIndex;
Let us first create a table −
mysql> create table demo67 −> ( −> id int, −> user_name varchar(40), −> user_country_name varchar(20) −> ); Query OK, 0 rows affected (0.72 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo67 values(10,'John','US'); Query OK, 1 row affected (0.19 sec) mysql> insert into demo67 values(1001,'David','AUS'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo67 values(101,'Mike','UK'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo67 values(102,'Carol','AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo67 values(110,'Chris','US'); Query OK, 1 row affected (0.36 sec) mysql> insert into demo67 values(105,'David','AUS'); Query OK, 1 row affected (0.08 sec)
Display records from the table using select statement −
mysql> select *from demo67;
This will produce the following output −
+------+-----------+-------------------+ | id | user_name | user_country_name | +------+-----------+-------------------+ | 10 | John | US | | 1001 | David | AUS | | 101 | Mike | UK | | 102 | Carol | AUS | | 110 | Chris | US | | 105 | David | AUS | +------+-----------+-------------------+ 6 rows in set (0.00 sec)
Here is the query for MySQL limit to display the first three rows −
mysql> select *from demo67 limit 0,3;
This will produce the following output −
+------+-----------+-------------------+ | id | user_name | user_country_name | +------+-----------+-------------------+ | 10 | John | US | | 1001 | David | AUS | | 101 | Mike | UK | +------+-----------+-------------------+ 3 rows in set (0.00 sec)
Advertisements