MySQL Forums
Forum List  »  Newbie

ORDER BY (SELECT ...) -- asc/desc inverted?
Posted by: Felix
Date: April 01, 2005 11:25AM

Can anyone tell me why this ends up sorting the returned rows in reverse alphabetical order?:

SELECT type,value FROM attributes WHERE linkedCard=$cardID ORDER BY (SELECT name FROM types WHERE id=type);

$cardID: some integer
attributes table: type is int, value is a string
types: name is a string, id is int; for every possible value of type that occurs in attributes there is exactly one corresponding row in types, so this will always return a row and only one row, and name will always be a string in the same charset as everything else (in this case english/latin1/the default/whatever)

The following also returns the same (reversed) order as above:

SELECT type,value FROM attributes WHERE linkedCard=$cardID ORDER BY (SELECT name FROM types WHERE id=type) ASC;

and putting DESC instead of ASC sorts them in ascending alphabetical order (which is what I want). I couldn't find any mention of ORDER BY (SELECT ...) in the docs or on these forums, but I'm pretty much a newbie so I don't know if this should be a bug report or not.

Options: ReplyQuote


Subject
Written By
Posted
ORDER BY (SELECT ...) -- asc/desc inverted?
April 01, 2005 11:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.