LIMIT and OFFSET tutorial in php

SELECT with LIMIT Syntax :

 SELECT column1, column2, column3...FROM table_name WHERE condition LIMIT number;


If we want to select Limited number of records then we can use LIMIT from table name "personal" as shown below sql query :

SELECT * FROM personal LIMIT 5;


If we want to select Limited number of records with any specific condition like city = "Agra" using LIMIT from table name "personal" as shown below sql query :

SELECT * FROM personal WHERE city = "Agra" LIMIT 7;

We can order in Ascending Order to above records using ORDER BY from table name "personal" as shown below sql query :

SELECT * FROM personal WHERE city = "Agra" LIMIT 7 ORDER BY name;


SELECT with OFFSET Syntax :

SELECT column1, column2, column3...FROM table_name WHERE condition LIMIT offset, number;


If we want to select particular number of records and select from any particular index of records from table name "personal" then we can use OFFSET as shown below sql query :

SELECT * FROM personal LIMIT 3, 3;

Here above First 3 means From which index the records will be select and second another 3 means number of records to select.

Comments

Popular posts from this blog

SubQuery with EXISTS and NOT EXISTS in PHP

UNION and UNION ALL in PHP

Classes and Objects in PHP OOPS