Jump to content

[SOLVED] quick LIMIT question


TempleDMDKrazd

Recommended Posts

pretend i have 1000+ rows in my table and i want to list the 500th+ to the last row

 

my book told me to do the following(assuming customer is the table name)

 

select * from customer limit 500, -1;

 

mySQL gives me a syntax error. how do i list from the 500th+ to the last row?

 

thanks

Link to comment
Share on other sites

first of all... how were you able to arrange the fetched rows?

 

without ORDER BY, how can you be certain that the results given are always of the same order?

 

with ORDER BY, you can specify ascending or descending and specify then LIMIT which ever order you want. :)

Link to comment
Share on other sites

first of all... how were you able to arrange the fetched rows?

 

without ORDER BY, how can you be certain that the results given are always of the same order?

 

with ORDER BY, you can specify ascending or descending and specify then LIMIT which ever order you want. :)

 

thanks for going off subject...the key is using auto_increment so the results are always the same order...i just asked a simple question and you made it more difficult by going to a brand new subject which doesn't even answer my question.

Link to comment
Share on other sites

thanks for going off subject...the key is using auto_increment so the results are always the same order...i just asked a simple question and you made it more difficult by going to a brand new subject which doesn't even answer my question.

 

i see, so you have the id, its not really off subject since what you need to do is

 

ORDER BY the_id DESC LIMIT 500

 

that's what am trying to point out. but anyway, good thing for you things work right away, way to go!

Link to comment
Share on other sites

Bluejay is absolutely correct without defining a method of ordering your query by your LIMIT is arbitrary in the fact that it could really be a random selecting of the same data set at a different point.

 

MySQL may by default order by the primary key if no ORDER BY is stated by why would you write something so  sloppy if you don't know if mysql does order by primary key by default (I have no clue personally)

Link to comment
Share on other sites

MySQL may by default order by the primary key if no ORDER BY is stated by why would you write something so  sloppy if you don't know if mysql does order by primary key by default (I have no clue personally)

 

I don't know to whom you pertain to or what you mean, eheh sorry.

 

Yes, adding primary key (auto-increment) without specifying ORDER BY will automatically ordered by its PK but it will be in ascending order. since what is needed is the bottom 500, i specified the ORDER BY the ID but this time descending order, and by adding LIMIT then, you will get the bottom 500.

 

Well, things did work for them, so good thing for them.

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.