473,320 Members | 1,950 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,320 software developers and data experts.

ORDER BY problem

I have table X with UNSIGNED INT column C. I want to order by C ASC,
but have the 0 value last. So, I thought that this should work:

SELECT *, (C-1) AS o from X ORDER BY o;

but it doesn't. Doing a SELECT on (C-1) shows an extremely large
POSITIVE integer value where C=0, as I expected from an UNSIGNED column.
But it is ordered first (as -1). Is this intended behavior? Am I
doing something wrong? I worked around it for now with:

....ORDER BY C>0 DESC, C ASC;

but my curiosity is aroused... And which is faster, anyway?

Thx

P.S. Originally (accidentally) posted in m.d.mysql-win32, sorry
Jul 23 '05 #1
1 1095
hoonew wrote:
Doing a SELECT on (C-1) shows an extremely large
POSITIVE integer value where C=0, as I expected from an UNSIGNED column.
But it is ordered first (as -1). Is this intended behavior? Am I
doing something wrong? I worked around it for now with:

...ORDER BY C>0 DESC, C ASC;
Try ORDER BY CAST(C-1 AS UNSIGNED)

You could also use ORDER BY IF(C = 0, 999999999, C)
but my curiosity is aroused... And which is faster, anyway?


Why don't you do some timings and tell us which is faster. ;-)

Seriously, many performance issues depend on the distribution of data
values in your database, so the best method of determining which is
fastest is to try it on _your_ database and measure the speed for yourself.

Regards,
Bill K.
Jul 23 '05 #2

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

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
2
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer...
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
5
by: tilak.negi | last post by:
We have one single hash (#) table, in which we insert data processing priority wise (after calculating priority). for. e.g. Company Product Priority Prod. Qty Prod_Plan_Date C1...
2
by: champ.supernova | last post by:
Hi, I was hoping someone could help me with what I'm sure is a very simple problem...I just can't seem to find the syntax! I'm wanting to update the rows in 'tbl_consolidate' from 'tbl_hold',...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
4
by: Philippe | last post by:
Hello, I encounter a problem that I cannot solve myself... The problem is the following: I make a table: several records: the first field is always a number, the following field is always...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
7
by: CDMAPoster | last post by:
I have a form in A97 that requires many textboxes and comboboxes (about 300). The customer insists on seeing all the information on one form so I can't break it up into several forms. Neither...
6
by: p_adib | last post by:
hello. I have 3 files: parent.cpp child.cpp driver.cpp I am working in visual C++ 6.0 and have all the files in one same project. When I ask the IDE to biuld my project, it compiles the code...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.