Solved

Wrong "order by" results

Posted on 2006-07-07
5
134 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now