![]() |
MySQL problem
I got a simple problem (at least it should be).
I just need to select a record from a table by it's location in the table. ie I may need to look at the 6th record or the 10th record. However, I don't wanna create a field for this. Can this be done? I've looked everywhere and it's either so simple that people haven't bothered to say how or it can't be done with a single command. Any help extemeley apprecited. BTW - I tried format c: and it didn't help :winkwink: |
have a link to MySQl info here http://superbooger.com/sponsors.html
|
Thanks Fletch. I've been at that site most of the evening and can now do just about every kind of mega complex search and sorting I want except the (should be simple) thing above. Maybe I need a drink....now where's that French beer gone.....
|
Just end your query with
LIMIT 10, 1 will return the 11th record LIMIT 10, -1 will return the 11th record through end of table Cheers! |
boldy solution was much smarter
:thumbsup |
Knew it had to be simple. Ta very much :)
|
select table
from shithead where you're fucked up this will do it! |
Right.. keeping in mind of course, that the order of rows in a table may change arbitrarily at any time.. specially after table optimizations.
|
Quote:
from shortbus where comment = 'stupid' order by rand() |
Tipsy. Your questions is a little misleading...
There is no such thing as a position in tables - in relational databases. You can not say a record is the 10th (or whatever) record in a table (or a select). The fact that a record is the 1st or 10th in a select that is NOT an "ORDER"ed select is a matter a chance and you SHOULD NOT - under any circumstances - count on it being consistently so.. I recommend the folowwing... 1) order(sort) the table by someithing - anything would do if you dont have a valid field (like ID). "ORDER BY ____ [DESC]". ____ is a field name, DESC is optional for reverse ordering 2) LIMIT x,y - like boldy suggested will give you the -1 record after skipping x records. -1 records means: 1 record BACK. if you do LIMIT 10,5 meains records 11..15 in the select result. Not using ORDER is also legitimate but DONT count of results being consistent. It will probably be so, but if you "check" the table or restore it from backup - results may change. actually ORDER is quite natural in many/most queries anyway - but if you dont care about consistency - not using ORDER may save you time/cpu |
Yes, you should always use ORDER BY when using LIMIT or the results aren't predictable.
I'm trying to get tech-chatter for porn people in channel #porntech on irc.theadultwebmaster.com / chatnet.sextracker.com |
Quote:
|
Heh.. no-one ever gets it when I say it.. haha.
|
Quote:
The query is immediately after finding the place in the table and seems to work at least 99.9% of the time which is more than enough for the function it's used for. Sorting the records by ORDER would create far more problems than it solved with some major re-writing being involved. Handy for future ref though :) |
| All times are GMT -7. The time now is 06:19 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123