Jump to content

Archived

This topic is now archived and is closed to further replies.

Ham

Using "Limit"

Recommended Posts

I'm trying to return 10 rows from a table starting at a primary key id with this query:

 

select * from table_name limit $primary_key, 10;

 

...but it does not work.

 

Please show me how!

 

 

Thanks,

 

Ham

Share this post


Link to post
Share on other sites

the limit x,y syntax only works with offsets (row number). If there was no deletions in your table, this would work fine, but if some items were deleted, an id would not be the correct offset anymore.

 

maybe this is what you need:

SELECT * FROM table_name WHERE id >= $primary_key ORDER BY id ASC LIMIT 10;

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.