I'm using this query:
SELECT * FROM `tutorials` ORDER BY `chars` DESC
the chars field holds a number value
The problem i'm having is that it's not ordering the way it should because there are high values below the lower values like so:
5435
2456
11254
Why isn't 11254 at the top?
[SOLVED] Ordering problem
Moderator: General Moderators
-
sk8erh4x0r
- Forum Commoner
- Posts: 43
- Joined: Wed May 26, 2004 8:27 pm
[SOLVED] Ordering problem
Last edited by sk8erh4x0r on Thu Aug 11, 2005 4:42 pm, edited 2 times in total.
what type is "chars" it looks like its a character string, so its sorting "alphabetically" not numerically. You might be able to cast it to an integer to make it sort properly. In PostGreSQL I'd try
but I don't know the syntax fo MySQL.
Code: Select all
SELECT * FROM tutorials ORDER BY chars::INT DESC;- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
MySQL ghetto quickie:
Code: Select all
SELECT * FROM tutorials ORDER BY chars+0 DESC;