Use LIMIT for pagination in MySQL query

I want my results to show the “page” at a time; I want the page number to be a parameter (in a prepared JDBC statement). Consider the following snippet

SELECT * FROM thread t ORDER BY t.id LIMIT ((? - 1) * 20), 20

Ideally for page 1, this will result in LIMIT 0, 20.

When i test

SELECT * FROM thread t ORDER BY t.id LIMIT ((1 - 1) * 20), 20

They tell me that I have a syntax error. I don’t understand what it can be - it's just simple math. All he tells me is

ERROR 1064 (42000): You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use next to '((1 - 1) * 20), 20' on line 1

What am I doing wrong with my proposal LIMITand how to fix it?

+6
3

MySQL LIMIT.

http://dev.mysql.com/doc/refman/5.7/en/select.html:

LIMIT , SELECT. LIMIT , , :

  • LIMIT ? -.

  • LIMIT .

Java.

+9

.

. :  MySQL Math COUNT (*) LIMIT

javascript - (.. ), : limit 0,20 limit 21,20 ...

, get URL- www.example.com?page=1

offset = (page - 1)*20 ;
row_count = 20;
select * from table limit (offset, row_count);
+12

,

SELECT column FROM table 
LIMIT {someLimit} OFFSET {someOffset};

, № 1 ( 1-10), 0, 10;

SELECT column FROM table 
LIMIT 10 OFFSET 0;

№ 2 ( 11-20), 10, 10.

SELECT column FROM table 
LIMIT 10 OFFSET 10;
+7

All Articles