FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Reading MySQL values in reverse





{name here}
How would I go about reading a MySQL table's values in reverse for my site's updates?
Rhysige
Well if the stuff has an ID then just put ORDER BY `ID` DESC into your query
hexkid
{name here} wrote:
How would I go about reading a MySQL table's values in reverse for my site's updates?

MySQL does not return values in any specific order (unless you tell it otherwise).

The same SELECT may return the rows in a different order every time it executes, so there really is no such thing as "reverse".

The rows will be returned unordered, unless you ORDER them BY something ASCendingly or DESCendengly Smile
Rhysige
Actually I believe they Typically order by the order they where entered into the database.. if it wasnt late at night I would do a test.. mabye some other time.
Kaneda
Rhysige wrote:
Actually I believe they Typically order by the order they where entered into the database.. if it wasnt late at night I would do a test.. mabye some other time.


Typically, yes. Guaranteed, not really Smile The SQL standard doesn't supply any idea of "default order" on SELECTs, and even mySQL isn't intentionally implemented to have such a default order. The reason it works anyway is pure luck in terms of the way mySQL stores the data - switch to Oracle, and you'll pretty much get a new sorting order every time you do the same SELECT.

Reason being that there's no point in spending processing time sorting a result set if the user doesn't need it. Hence, the DB engine will return rows in the order it finds them (after going through WHERE, LIMIT etc. of course).

In mySQL, that usually means the in which the data was entered into the table (because that's the order mySQL stores it in the DB files). Wouldn't know if there's any exceptions, since I always have an ORDER BY if I need it, and I haven't ever seen anyone complain about this issue online.

Also, any external DB tools (like data restoration etc.) might change the order of data in the file, after which mySQL won't "know" in what order you entered the data Smile
{name here}
EDIT: PhpMyAdmin Fixed the problem
Related topics
php admin and mysql admin console
E-Cards with PHP & MySQL
HTTP AUTH with PHP and mySQL
Build an online dictionary by PHP/MySQL
Make search engine With PHP and mySQL, for your site
How To : Improve Your PHP Programming
[OFFICIAL] What are you currently reading?
Importing an existing database...
MySQL statement error (got me going)
PHP Tutorial: Basic Shoutbox w/ MySQL
MySQL DB Backup script - minor problem
Power supply problems
mySQL help needed, any other good database thing?
transfering mysql values form one table to another with php
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.