Jump to content


Photo

Using "Limit"


  • Please log in to reply
1 reply to this topic

#1 Ham

Ham
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2005 - 06:09 PM

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

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 19 September 2005 - 11:05 PM

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;

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users