0

Trying to add offset to a mysqli query, but it won't return any rows:

Works:

SELECT * FROM posts WHERE published='1' ORDER BY id DESC

Does not work:

SELECT * FROM posts WHERE published='1' ORDER BY id DESC OFFSET 20
2
  • 3
    Yep, you can't just make up syntax Commented Nov 28, 2020 at 20:08
  • OFFSET is an addition to LIMIT. Commented Nov 28, 2020 at 20:15

1 Answer 1

2

You can try this syntax instead as OFFSET needs LIMIT keyword:

SELECT * FROM posts WHERE published='1' ORDER BY id DESC LIMIT 40 OFFSET 20;

This means that it will return the limit of fetched rows 40 only and skipping the first 20 rows.

You can check this link https://www.w3schools.com/php/php_mysql_select_limit.asp that can help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.