Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Problem On Mysql "order By"
teob
post Jan 15 2005, 04:19 AM
Post #1


Newbie [Level 3]
***

Group: Members
Posts: 43
Joined: 15-November 04
Member No.: 2,292



Can someone please help...?
I have a problem with using "ORDER BY" in mysql...
CODE
SELECT * FROM `foo` WHERE b='abc' ORDER BY 'number' ASC

i want to sort the table out by the value in "number" which is a number..

but it came out to be sort by like this way...
1->10->2->20
it only sort out the front digit....

but what i want is it will sort by how great the number is like this...
1->2->3........->10....->20

sorry my english isn't good enough...to describe my problem properly...
hope you can understand and help me on this.....thx
Go to the top of the page
 
+Quote Post
NilsC
post Jan 15 2005, 05:29 AM
Post #2


Administrator
*********

Group: Members
Posts: 377
Joined: 28-December 04
From: USA
Member No.: 2,992



I think you have the syntax wrong. Are you creating a query in mySQL? or calling from a php script?
CODE
SELECT expressions_and_columns FROM table_name
[WHERE some_condition_is_true]
[ORDER BY some_column [ASC | DESC]]
[LIMIT offset, rows]


So yours should be:
CODE
SELECT * FROM foo WHERE b = 'abc' ORDER BY number ASC;


theoretical questions can have only theoretical answers. You would get better help if you use the table names that you have problem with!

Here is a nice link to a tutorial in your problem:
The select statement.

Nils
Go to the top of the page
 
+Quote Post
Zenchi
post Jan 15 2005, 06:54 AM
Post #3


Super Member
*********

Group: Members
Posts: 498
Joined: 23-August 04
Member No.: 878



This is how mysql sees the way to order those numbers accordingly:

2(null)(null), 20(null), 200, 21(null), 210(null)

Catch my drift? It's like an ftp directory where you see files listed by numbers, and it looks all messed up. It's not. I believe it has to do with the hexidecimal coding, but again, don't quote me on that.
Go to the top of the page
 
+Quote Post
bjrn
post Jan 18 2005, 04:43 PM
Post #4


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



QUOTE(Zenchi @ Jan 15 2005, 08:54 AM)
This is how mysql sees the way to order those numbers accordingly:

2(null)(null), 20(null), 200, 21(null), 210(null)

Catch my drift? It's like an ftp directory where you see files listed by numbers, and it looks all messed up. It's not. I believe it has to do with the hexidecimal coding, but again, don't quote me on that.
*


If number is a string field you have a problem. The other thing could be that you should have "ORDER BY number" instead of "ORDER BY 'number'" (without the single quotes). Although that should give an SQL error if it was wrong... Strange...
Go to the top of the page
 
+Quote Post
iGuest
post Nov 29 2007, 03:00 PM
Post #5


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



I had a similar situation with a string field like "SomeString Number", where Number had values like 1, to, 3, ... 55 ...(max to characters) and SomeString had a fixed length = n.

I used a update query like this one:

<code>
update Table set Field = concat(left(Field, n), " 0", right(Field, 1))
where lenth(Field) = n+to;
<code/>

n+to = n (SomeString) + 1 (space) + 1 (for numbers with 1 digit)

So, my Field has values like "SomeString Number", where Number had values like 01, 02, 03, ... 55 ...(exactly to characters) and ORDER BY work well now.

I think this is useful for someone , in this particular situation :)

-gims
Go to the top of the page
 
+Quote Post
gogoily
post Dec 6 2007, 05:51 AM
Post #6


Member [Level 2]
*****

Group: Members
Posts: 76
Joined: 30-October 05
Member No.: 13,571



try set the type of "number" to int
I think the type of your "number" is varchar or something.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Increment A Mysql Column(6)
  2. Can You Add Images Into A Mysql Database?(20)
  3. Creating Profiles In Php/mysql ?(7)
  4. Php Search Engine Script For Mysql Database(11)
  5. How To Delete A Row In Mysql.(4)
  6. Importing .csv Into Mysql Database(6)
  7. Editing Information In A Mysql Database And Deleting Rows(5)
  8. Putting Data Of 2 Pages In Mysql At Once(1)
  9. Mysql Query(2)
  10. Simple Mysql Query Limiting(9)
  11. Some Mysql Basics(4)
  12. Php, Mysql, Apache(4)
  13. Php And Mysql Applications(3)
  14. Getting Php 5 To Work With Mysql(0)
  15. Problem With A Mysql Join(2)
  1. The Artists Tutorials :mysql Basic Commands(0)
  2. [mysql]get Id Of Loged In User?(7)
  3. [mysql/php]need Som Basic Help(13)
  4. [php/mysql]id Trouble [resolved](3)
  5. Mysql Won't Update(4)
  6. Php + Mysql Question!(4)
  7. Tools Needed!(9)
  8. Best Sites For Learning Php-mysql(4)
  9. Php And Mysql Programming(2)
  10. Best Php And Mysql Editor For Noobs(6)
  11. Html Form!(4)
  12. Mysql Error(3)
  13. Create Table - Mysql Code - Help(1)


 



- Lo-Fi Version Time is now: 27th July 2008 - 02:21 AM