473,410 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Sorting correctly...

I am running a long query that has a combination of results.

The results that I'm sorting by is the "Room Number". This room number
could be a number or even something like "Office". (This information
is used for schools, and their rooms aren't always labelled by true
numbers.).

The problem I am having is ... the numbers will not sort from actual
"highest to lowest". They go something like this: "1, 10, 11, 12, 13,
14, 15, 2, 20, 3, 4, 5, 6, 7, 8, Office, etc". I'd like to sort them
"ASCII-betically".

Is there anything in MySQL to assist me with this, or will I need to
code this in. This is an older project not written by myself and there
are many reworkings I'd have to do to get it to work as needed. So, a
quick addition to the SQL would be very nice.

Thank you.

Oct 14 '05 #1
4 2076
>The results that I'm sorting by is the "Room Number". This room number
could be a number or even something like "Office". (This information
is used for schools, and their rooms aren't always labelled by true
numbers.).

The problem I am having is ... the numbers will not sort from actual
"highest to lowest". They go something like this: "1, 10, 11, 12, 13,
14, 15, 2, 20, 3, 4, 5, 6, 7, 8, Office, etc". I'd like to sort them
"ASCII-betically".


Given the most reasonable definition of "ASCII-betically" I can
come up with, that list *IS* sorted (as a bunch of strings). If
you think it isn't, explain why not, and what you DO want.

Gordon L. Burditt
Oct 14 '05 #2
kr*****@gmail.com wrote:
The results that I'm sorting by is the "Room Number". This room number
could be a number or even something like "Office". (This information
is used for schools, and their rooms aren't always labelled by true
numbers.).

The problem I am having is ... the numbers will not sort from actual
"highest to lowest". They go something like this: "1, 10, 11, 12, 13,
14, 15, 2, 20, 3, 4, 5, 6, 7, 8, Office, etc". I'd like to sort them
"ASCII-betically".


Try something like this:

SELECT room_num FROM myTable
ORDER BY CAST(room_num AS UNSIGNED INTEGER);

Casting "Office" as an integer appears to yield a value of 0, which
makes it sort earliest in the list.

I tested this with MySQL 5.0.10.

Regards,
Bill K.
Oct 14 '05 #3
I would like them to show up as. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
20, 30, Office.

Sorry if I used the wrong terminology and caused confusion.

Oct 14 '05 #4
>I would like them to show up as. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
20, 30, Office.

Sorry if I used the wrong terminology and caused confusion.


Now throw into the mix Offal, oFFice, 11Cat, Office21, Office2, Office02,
Office22, and 1Office2. How should those be ordered?

You can force the field to be ordered as a number; one way being
ORDER BY room+0
but this leaves the room numbers beginning with letters in a possibly
random order.

Gordon L. Burditt
Oct 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
1
by: VMI | last post by:
How can I sort a table column correctly when the table has values like "0", "A1", "AA-1", "B21", "3C", 4-32A", "1", "11-1", 2-A", etc... The table will then be loaded to a grid and that's when...
0
by: Daniel Bass | last post by:
I've already posted this in the asp forum, and other asp.net forums on the net with no luck... I've got a data grid, with paging, and sorting allowed. I can find loads of examples, and have...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
3
by: Carlos | last post by:
Hi all, I currently have a Gridview that doess sorting correctly using several fields. However, I do have a checkbox field that when it is checked I do not know how to make its value to persist...
2
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column...
4
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create...
3
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2 for C# windows application. One of my column on the Listview control has numericstring. Other columns are sorting correctly except this one. It seems to be sorting...
5
by: Mike | last post by:
I have several datagirds that allow sorting on two date columns. The sorting works but its not showing the newest date first when I sort. For example if I have dates in my column as 01/01/2008...
5
by: Tom Shelton | last post by:
On 2008-04-22, Tom Shelton <tom_shelton@YOUKNOWTHEDRILLcomcast.netwrote: Nevermind... My needs were simple, so I just changed all the columns to Programmatic and am handling the sorting myself :)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.