Mysql - Uses of Offset ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santhanalakshmi
    New Member
    • May 2009
    • 147

    Mysql - Uses of Offset ?

    What is the purpose of OFFSET in mysql ?

    Code:
       mysql>select * from info oFFSET 3 ;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3' at line 1
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    Learn how to implement SQL pagination using LIMIT and OFFSET clauses, applicable to both MySQL and PostgreSQL databases.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      Also see the part about LIMIT in the Manual (12.2.8. SELECT Syntax)

      Basically, the MySQL syntax to LIMIT the rows a result set will return goes:
      [code=mysql]SELECT ... LIMIT x, y[/code]
      Where "x" is the number of rows you want returned and "y" is the offset. (Offset meaning; the number of rows to remove from the top of the list.)
      For example, if you have a 100 rows in the original result set a "LIMIT 10, 20" would return rows #21 through #30. That is; 10 rows starting after #20.

      For compatibility with PostgreSQL, you can optionally replace the comma in the LIMIT syntax with the OFFSET keyword.
      [code=mysql]SELECT ... LIMIT x OFFSET y[/code]
      However, this is optional. You don't need to do this unless you plan on building PostgreSQL compatible queries.

      Comment

      • santhanalakshmi
        New Member
        • May 2009
        • 147

        #4
        hi,
        I got it....thanks for your response

        Comment

        Working...