TempleDMDKrazd Posted July 19, 2008 Share Posted July 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
vikramjeet.singla Posted July 19, 2008 Share Posted July 19, 2008 refer to limit clause in following url: http://dev.mysql.com/doc/refman/5.0/en/select.html Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted July 19, 2008 Share Posted July 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
Zwiter Posted July 19, 2008 Share Posted July 19, 2008 [deleted] ^^ Quote Link to comment Share on other sites More sharing options...
TempleDMDKrazd Posted July 19, 2008 Author Share Posted July 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
TempleDMDKrazd Posted July 19, 2008 Author Share Posted July 19, 2008 refer to limit clause in following url: http://dev.mysql.com/doc/refman/5.0/en/select.html thanks! that answered my question perfectly.... Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted July 19, 2008 Share Posted July 19, 2008 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! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 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) Quote Link to comment Share on other sites More sharing options...
Zwiter Posted July 20, 2008 Share Posted July 20, 2008 SELECT A.* FROM customer AS A LEFT JOIN ( SELECT customer_id FROM customer LIMIT 500 ) AS B USING ( customer_id ) WHERE B.customer_id IS NULL Z. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted July 21, 2008 Share Posted July 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
Zwiter Posted July 21, 2008 Share Posted July 21, 2008 bluejay, you dont read his post, he need the last records, BEGINING at the 500th. My query is the only one working at the moment. Z. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted July 21, 2008 Share Posted July 21, 2008 oh my bad. thanks for the clarrification. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.