Jump to content

Ignoring a selected amount of rows


CanMan2004

Recommended Posts

Hi all

Is there a way to put something into a query which ignores the first defined number of results.

For example, if I have the following query

[code]SELECT * FROM mydata WHERE `name` = '".$name."' AND allowed = 'YES' ORDER BY `idnum` DESC LIMIT 20[/code]

Is there a way to ignore the first x number of results which are returned.

x is a number, so if your results brought back id numbers

1
2
3
4
5
6

and you said for it to ignore the first 4, then it would return

5
6

Can this be done?

Thanks in advance

Ed
Link to comment
Share on other sites

Yeah, you provide LIMIT with two arguments

[color=green][b]LIMIT 4, 20[/b][/color]

The first is the offset you want and the second is the amount of rows to return.

It returns rows based on the offset of your dataset, not the entire table.  So if you had the following data:

ID, Name
1    Rich
2    Paul
3    Sam
4    Ryan
5    Dave

[color=maroon]SELECT name FROM table ORDER BY id LIMIT 1, 1[/color] you'd get Paul, but if you had SELECT name FROM table WHERE name LIKE 'R%' ORDER BY name LIMIT 1, 1 then you'd get Ryan.

I hope that makes sense

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.