Mysql query for table row range

This may be a very simple question, but I'm struggling with queying specific rows in a table based only on a range of rows.

Let's say I have an ABC table where I populated 1000 rows. Now I need a sql query so that I can get the first 100 rows (this is a range from 1 to 100), and then the next 100 (from 101 to 200), etc., until I finish with all the rows. And this should be done without querying / filtering the table id or any column id.

I can't figure it out because I am only trained on querying specific columns in the WHERE clause, so it would be helpful if someone could with plz

+4
source share
2 answers

You must use the LIMIT in a SELECT query. MySQL allows you to set two parameters for a sentence, offset (first parameter) and the number of rows to fetch (second parameter).

 SELECT * FROM `ABC` LIMIT 0, 100 SELECT * FROM `ABC` LIMIT 100, 100 SELECT * FROM `ABC` LIMIT 200, 100 -- etc... 

However, you cannot guarantee the order of these rows unless you sort by one or more specific columns (columns) using the ORDER BY .

Read more about the SELECT here: http://dev.mysql.com/doc/refman/5.6/en/select.html

+6
source

you can use limit in mysql.

limit accepts 2 parameters.

this will return 1-10 records.

 select * from abcd limit 10 

this will return 10-20 records.

 select * from abcd limit 10,10 

this will return 20-30 records.

 select * from abcd limit 20,10 
+3
source

Source: https://habr.com/ru/post/1482233/


All Articles