MySQL limit cffunction for Query and QoQ's

Query of a Query functionality was introduced in ColdFusion 5 and it gives the developer the ability to re-query a returned recordset. While it does implement the core set of SQL SELECT commands the one bit of functionality I miss is MySQL's Limit function (I miss this in ANY relational database thats not MySQL as it makes paginiation a doddle).

Limit in MySQL works as such:

view plain print about
1SELECT * FROM myTable LIMIT 0, 10

The above code will display the first 10 results from your your (table is 0 indexed)

view plain print about
1SELECT * FROM myTable LIMIT 5, 5

Starting from the 5th record this will bring back rows 6, 7, 8, 9, and 10

Posted: 17-Jul-2008

View: 3502

Permalink: here

Comments

*cough* cflib *cough*

#1 Raymond Camden
17/Jul/08 8:00 AM

Handy function Andy! It is annoying that every DB handles this differently, I put together a list a while back with all the different ways to limit results on different dbs: http://www.petefreitag.com/item/59.cfm

#2 Pete Freitag
17/Jul/08 9:36 AM

You can also use the maxrows attribute of CFQUERY on your QofQ to get the limit/top functionality for free. There's not an attribute that supports offset, I use non-offset limits more than I use offset limits, so it's quite useful.

#3 Barney
17/Jul/08 11:41 AM

@Raymond Camden thats a nasty cough you've got there :) I've submitted it to CFLIB ... though if the submission is dodgy, sorry :)

#4 Andy Jarrett
17/Jul/08 3:58 PM