1

I am trying to select records from database table here is query

 $select = $this->newDbConnection()
        ->select()
        ->from($this->getDbPrefix() . 'test', '*')
        ->order('id', 'ASC')

I want to limit result records lets say 500 recoreds per request.

final query would look like this

SELECT `test`.* FROM `test` ORDER BY `id` ASC LIMIT 0,500

How I can set limit**(LIMIT 0,500)** by magento2 way?

1 Answer 1

3

You can use the below code:

$select = $this->newDbConnection()
        ->select()
        ->from($this->getDbPrefix() . 'test', '*')
        ->order('id', 'ASC')
        ->limit(500, $offset);

Hope this helps.

Note: Above code is not tested but it should work.

1
  • Thank you that worked! Commented Jan 31, 2020 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.