1

I'm running php code over ibm i series server.

I've been trying to limit the number of records i'm getting using LIMIT. I used this query (which works just fine without "LIMIT") :

$query="SELECT slgrpn,slfrkn,slftyp,slfsze,slpqty,slpwht,slentp,slqplt,sltots,slfrmn,slcstn,sldtrd FROM HUTAYOSI.$file ORDER BY slcstn ASC LIMIT 10";

And I got this error:

Token LIMIT was not valid. Valid tokens: FOR USE SKIP WAIT WITH FETCH OPTIMIZE. 

Any suggestions?

Thanks in advance

1
  • have you tried without the order by clause? Commented Oct 16, 2011 at 7:35

2 Answers 2

5

It looks like your using DB2. For this you will have to use FETCH FIRST 10 ROWS ONLY instead of LIMIT 10

so your query will look like this:

$query="SELECT slgrpn,slfrkn,slftyp,slfsze,slpqty,slpwht,slentp,slqplt,sltots,slfrmn,slcstn,sldtrd FROM HUTAYOSI.$file ORDER BY slcstn FETCH FIRST 10 ROWS ONLY";

Best regards Jonas

Sign up to request clarification or add additional context in comments.

Comments

1

Are you sure you are connecting to a MySQL database? Your error message looks like it is comming from a DB2 database.

If your database is DB2 then to limit the result set being returned, MySQL uses the keyword, LIMIT, while DB2 Express uses FETCH FIRST n ROWS to limit the result set being returned.

And as such your query should look like this:

$query="SELECT slgrpn,slfrkn,slftyp,slfsze,slpqty,slpwht,slentp,slqplt,sltots,slfrmn,slcstn,sldtrd FROM HUTAYOSI.$file ORDER BY slcstn FETCH FIRST 10 ROWS ONLY";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.