Advertisements

Archive

Posts Tagged ‘take’

MYSQL : How to skip first 10 records from a SELECT query and take next 10?

October 4, 2017 Leave a comment

We know there are skip and take operators available in linq to skip and take

The Take operator is used to return a given number of rows from a object list and the Skip operator skips over a specified number of rows in object list.

var employee = (from emp in employeeContext.EMPLOYEEs

where emp.SALARY < 1300

select emp).Skip(2).Take(5);

Is there a way in MySQL to achieve the same like have the first 10 result from a SELECT query skipped and select next 10?

Answer : Yes we can use LIMIT with two parameter

Introduction to MySQL LIMIT clause

The LIMIT clause is used in the SELECT statement to constrain the number of rows in a result set. The LIMIT clause accepts one or two arguments. The values of both arguments must be zero or positive integers.

The following illustrates the LIMIT clause syntax with two arguments:

Let’s examine the LIMIT clause parameters:

  • The offset specifies the offset of the first row to return. The offset of the first row is 0, not 1.
  • The count specifies the maximum number of rows to return.

When you use the LIMIT clause with one argument, this argument will be used to determine the maximum number of rows to return from the beginning of the result set.

SELECT *  FROM table LIMIT count;

Use LIMIT with two parameters. For example, to return results 11-60 (where result 1 is the first row), use:

SELECT * FROM foo LIMIT 10, 50
Hope this help !
Advertisements