Reputation:
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
Upvotes: 1
Views: 387
Reputation: 11711
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";
Upvotes: 1
Reputation: 2734
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
Upvotes: 5