2

I've not yet found the right way to use ->range($offset,$limit) in a dynamic query to skip first result, but without limiting the resultset (LIMIT clause).

The only workaround I've found is to use an high value for LIMIT, for example:

->range(1,99999999);

(see my comment in Drupal API documentation: https://api.drupal.org/comment/49938#comment-49938)

What's the right sintax?

  • In pure SQL there is an OFFSET 1 that would do the trick. Works both with MySQL and PostgreSQL at least in their recent versions. And that's what Drupal uses. To bad it does not test for existence of second parameter, just assume both are there. I encourage you to make it a feature request in core's issue queue. – Mołot Jun 27 '13 at 7:09
2

You could do something like this:

// Begin query build
$query = db_select('node');
$query->fields('node', array('nid', 'title'));
$query->condition('type', 'article');
$query->condition('uid', 1);

// Get total count for query
$count = $query->countQuery()->execute()->fetchField();

// Execute range query
$start = 1;
$query->range($start, ($count - $start));
$result = $query->execute();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.