KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using OFFSET and LIMIT in SQL
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: May 21, 2013

OFFSET and LIMIT can be very powerful in SQL if used properly.

LIMIT is pretty self explanatory but lets brush up on the usage anyways; LIMIT is used to restrict the number of results. For example, if you only want 1 record in the result set you can specify LIMIT 1

OFFSET is the amount of data to be skipped before returning the result set. For example, if you want the first record you could specify OFFSET 0

Here is an example SQL statement of getting the first record:

Begin SQL
   SELECT Field_1
   from table_1
   LIMIT 1
   OFFSET 0
   into :TEST;

End SQL


Here is an example SQL statement of receiving the records 10 through 20:

Begin SQL
   SELECT Field_1
   from table_1
   LIMIT 10
   OFFSET 9
   into :TEST_array;

End SQL