Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Biology Forums on June 11, 2018, 12:18:25 PM

Title: SQL question
Post by: Biology Forums on June 11, 2018, 12:18:25 PM
Hi everyone,

Say I have a table with many rows, and I wanted to limit the query between rows 10,000 and 20,000 or 300 to 400, how would I change the LIMIT part to reflect that?
Title: Re: SQL question
Post by: vbgamer45 on June 11, 2018, 01:03:51 PM
LIMIT 10000, 20000
Title: Re: SQL question
Post by: albertlast on June 11, 2018, 01:49:03 PM
The fastest and litte complex way is to use Keyset Pagination:
https://www.citusdata.com/blog/2016/03/30/five-ways-to-paginate/
Title: Re: SQL question
Post by: Biology Forums on June 11, 2018, 04:16:09 PM
Thank you both.
Title: Re: SQL question
Post by: Biology Forums on June 13, 2018, 12:23:57 AM
Quote from: vbgamer45 on June 11, 2018, 01:03:51 PM
LIMIT 10000, 20000


Are you sure this will give me 10000 rows? I.e. 20,000 - 10,000 = 10,000?

Please when I write $count = mysql_num_rows($request); it gives me 20,000. I need the difference
Title: Re: SQL question
Post by: vbgamer45 on June 13, 2018, 12:25:31 AM
No it doesn't it should be
LIMIT 10000, 10000

Since the first returns 20k records

Title: Re: SQL question
Post by: Biology Forums on June 13, 2018, 09:01:34 AM
Maybe I'm not communicating what I want very well.

I'll try again. Pretend I want rows between 30 and 40. In other words, I want 10 row output between row 30 and 40, would I use

LIMIT 30, 40? I tried that already and it didn't work.
Title: Re: SQL question
Post by: Kindred on June 13, 2018, 09:26:37 AM
seriously... google is your friend. :P

https://www.w3schools.com/php/php_mysql_select_limit.asp
Title: Re: SQL question
Post by: vbgamer45 on June 13, 2018, 09:28:17 AM
Normally I use id's to return the rows i want rather than limit offsets. Limits i generally use with paging

Such as where id_msg >= 30 and id_msg <= 40
Title: Re: SQL question
Post by: Biology Forums on June 13, 2018, 10:23:00 AM
Quote from: vbgamer45 on June 13, 2018, 09:28:17 AM
Normally I use id's to return the rows i want rather than limit offsets. Limits i generally use with paging

Such as where id_msg >= 30 and id_msg <= 40


This works best for my needs, thanks for the idea.
Title: Re: SQL question
Post by: vbgamer45 on June 13, 2018, 11:04:23 AM
That is always the most efficient way as well.