How to Offset a Query in MySQL

How to Offset a Query in MySQL thumbnail
Use OFFSET to specify your query results.

When you build a query in MySQL, you can use the LIMIT clause to specify how many results you want to see. For example, you have a query that returns 1,000 results, but you only want to see 10 of those results. You could use the LIMIT clause to limit the results to just 10. The problem is that the LIMIT clause always returns the first results in the query result. If you want to specify results 11 through 20 instead of results 1 through 10, you need to add the OFFSET clause to your MySQL query.

Instructions

    • 1

      Log on to your computer and open MySQL. Open the database you want to work with.

    • 2

      Open the tables in your MySQL database and identify the fields you want to include in your query. Write those field names down exactly as they appear in the tables.

    • 3

      Go to the MySQL query tool and type your query using the LIMIT and OFFSET clauses. For instance, for a query to select the Last_Name field from the Employees table and display rows 11 through 20, you would type:

      SELECT Last_Name FROM Employees

      LIMIT 10 OFFSET 10

    • 4

      Review the results of the query. Change the settings in the query to display a higher number of rows, or to display a different group of results.

Related Searches:

References

  • Photo Credit David Sacks/Lifesize/Getty Images

Comments

Related Ads

Featured