Solved

Wrong "order by" results

Posted on 2006-07-07
5
139 Views
Last Modified: 2010-03-05
I have the following Perl code that takes the data from MySQL and sorts it:

$querystr = "select ID,Name,Description,PictureURL,InformationURL,Rate,10_Min,20_Min,Connect from $Table_Name order by 10_Min desc,Rate asc,Connect asc";
$sth = &sql($querystr);

For some reason the sorted results look like this (field 10_Min):

526
412
135
1342
125
95

Why is 1342 not on top of this list and what do I need to do to change in the code to have 1342 on top?



0
Comment
Question by:alosito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17060146
it's ordered in ASCII order, not numeric order. But it's not perl, it's SQL that is ordering the data. I'm not sure of the proper SQL command though to order it numerically.
0
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 100 total points
ID: 17065311
I'm not a MySQL guy, but try this:
$querystr = "select ID,Name,Description,PictureURL,InformationURL,Rate,10_Min,20_Min,Connect from $Table_Name order by CAST(10_Min AS UNSIGNED) desc,Rate asc,Connect asc";

If you have negative values, change UNSIGNED to SIGNED.

I hope this works :)
0
 
LVL 4

Expert Comment

by:NorCal2612
ID: 17073550
This worked for me:

select ID, Name, Description, PictureURL, InformationURL, Rate, cast(10_Min as integer), 20_Min, Connect
from $Table_Name
order by 10_Min desc, Rate asc, Connect asc



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question