Using LIMIT in SQL Query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
warrenk
Forum Newbie
Posts: 13
Joined: Wed Nov 01, 2006 8:46 am

Using LIMIT in SQL Query

Post by warrenk »

I am trying to paginate my query results. When I use the LIMIT in my SQL statement, I get the following error:

'Token Limit Was Not Valid'

From what I uderstand the LIMIT parameter can't be used with a ODBC_EXEC? If so, is there another parameter I can use in my SQL statement that allows me to specify starting record and limit the number of records in my results?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Queries are interpreted by the database, not the API. What database are you using?
warrenk
Forum Newbie
Posts: 13
Joined: Wed Nov 01, 2006 8:46 am

Post by warrenk »

I am trying to pull the results from a AS400 database.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

warrenk wrote:I am trying to pull the results from a AS400 database.
meaning: it's a DB2?

LIMIT is a mysql extension to sql.
Funny, IBM set up a page called
http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0602tham2/ wrote:Leveraging MySQL skills to learn DB2 Express: DB2 versus MySQL administration and basic tasks
http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0602tham2/ wrote:However, to limit the resultset being returned, MySQL uses the keyword, LIMIT, while DB2 Express uses FETCH FIRST n ROWS to limit resultset being returned
warrenk
Forum Newbie
Posts: 13
Joined: Wed Nov 01, 2006 8:46 am

Post by warrenk »

Volka,

You are correct...it is DB2.

This adds a twist to what I am trying to do. The LIMIT parameter made it so easy to paginate my results. Oh well...back to the drawing board.

Thanks for your help!
Warren
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Warren, you might consider the possibility of importing data from the DB2 table(s) into MySQL and then using the LIMIT feature of MySQL.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Or you might read an article about how to achive pagination with db2 ;)

http://www-128.ibm.com/developerworks/d ... alani.html
warrenk
Forum Newbie
Posts: 13
Joined: Wed Nov 01, 2006 8:46 am

Post by warrenk »

Volka,

Thanks for your help! I was just on the internet searching for a way to do this without the LIMIT. You saved me lots of stress!!!! :D

Warren
Post Reply