– Common Function Library Project

limit(inQry, arg1, arg2)

Last updated February 13, 2009


Andy Jarrett

Version: 2 | Requires: CF6 | Library: DatabaseLib

To be used on a recordset like a QoQ. Mimics MySQL's Limit function i.e. SELECT * FROM myTable LIMIT 0, 10 The above code will display the first 10 results from your table SELECT * FROM myTable LIMIT 5, 5 Starting from the 5th record this will bring back rows 5, 6, 7, 8, and 9. This functions aims to mimic this.

Return Values:
Returns a query.


<cfset qry = yourQuery />
<!--- Return rows 5-10 --->
<cfset newQuery = limit(qry, 5,5) />


Name Description Required
inQry Query to modify. Yes
arg1 Row to begin the limit. Yes
arg2 Number of rows to limit the result to. Yes

Full UDF Source:

 Mimics MySQL limit's function.
 v2 mods by Raymond Camden and Steven Van Gemert
 @param inQry      Query to modify. (Required)
 @param arg1      Row to begin the limit. (Required)
 @param arg2      Number of rows to limit the result to. (Required)
 @return Returns a query. 
 @author Andy Jarrett ( 
 @version 2, February 13, 2009 
<cffunction name="limit" returntype="query" description="WORKS LIKE MYSQL LIMIT(N,N)" output="false">
    <cfargument name="inQry" type="query" hint="I am the query" />
    <cfargument name="arg1" type="numeric" />
    <cfargument name="arg2" type="numeric" />
    var outQry = arguments.inQry;
    var a1 = arguments.arg1-1;
    if(arg1 GT 1){
        outQry.RemoveRows(JavaCast( "int", 0 ), JavaCast( "int", a1 ));
    outQry.RemoveRows(JavaCast( "int", arg2 ),JavaCast( "int", outQry.recordcount-arg2));
    return outQry;


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson