473,666 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ORDER BY

I have this list that i'm ordering by units_unit_id and is there way I can get
a natural order so that D4 and D5 comes before D12

Thanks,
Matt

+---------------+
| units_unit_id |
+---------------+
| D1 |
| D12 |
| D14 |
| D15 |
| D16 |
| D18 |
| D19 |
| D4 |
| D5 |
+---------------+
Jul 20 '05 #1
12 4135
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html
Jul 20 '05 #2
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html
Jul 20 '05 #3
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html
Jul 20 '05 #4
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.

"Aggro" <sp**********@y ahoo.com> wrote in message
news:Pe******** ****@read3.inet .fi...
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html

Jul 20 '05 #5
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.

"Aggro" <sp**********@y ahoo.com> wrote in message
news:Pe******** ****@read3.inet .fi...
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html

Jul 20 '05 #6
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.

"Aggro" <sp**********@y ahoo.com> wrote in message
news:Pe******** ****@read3.inet .fi...
Matias Silva wrote:
I have this list that i'm ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12


It is not a natural order, natural order is the one you are getting.
Easy way would be to change the table so that D and number would be in
different columns. Another way is to use some string manipulation
functions to parse string into character and a number and then order by
number. This might mean slow queries if you have many rows in your table
so first solution is better if it is possible to do.

left() right() and length() functions atleast are able to to do this.
I'm not sure if there is a better way to do it, you can look for such
functions from the manual:

http://dev.mysql.com/doc/mysql/en/String_functions.html

Jul 20 '05 #7
bobb wrote:
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.


...., D99, D100, etc.
--
Eric Lafontaine
mail http://cerbermail.com/?WaqHmkTe5E
Jul 20 '05 #8
bobb wrote:
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.


...., D99, D100, etc.
--
Eric Lafontaine
mail http://cerbermail.com/?WaqHmkTe5E
Jul 20 '05 #9
bobb wrote:
Great point Aggro...
My 2cents...
natural order for me is D01, D02, D03... D12, D13.. etc.


...., D99, D100, etc.
--
Eric Lafontaine
mail http://cerbermail.com/?WaqHmkTe5E
Jul 20 '05 #10

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

Similar topics

7
3654
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc. And i have things to offer, and to request. And a lot of ideas, but who needs them.... here's an example (from type_struct.py):
9
2726
by: Steven T. Hatton | last post by:
The following works: template <typename T> struct ID3M{ static const T ID; }; template <typename T> const T ID3M<T>::ID = {{1,0,0},{0,1,0},{0,0,1}};
15
4309
by: | last post by:
The data file is a simple Unicode file with lines of text. BCP apparently doesn't guarantee this ordering, and neither does the import tool. I want to be able to load the data either sequentially or add line numbering to large Unicode file (1 million lines). I don't want to deal with another programming language if possible and I wonder if there's a trick in SQL Server to get this accomplished. Thanks for any help. Mark Leary
27
11156
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
8
6808
by: kaosyeti | last post by:
i have a (hopefully) small problem. i have created a system where a user enters customer information into a table through a form. this table has no primary key. there are 9 fields on the form to be filled in, one of which is a date field. right now, i've been using this db myself and have entered only 10 days of sample data to check my calculations but i realized that there may be times when i need to add a record that was missed that...
104
10857
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 sorted by Numb. Everything I've read on the web suggests that including the TOP directive should enable ORDERY BY in views. Does someone have an idea why the sorting is not working correctly for this particular view? thanks. CREATE VIEW...
13
4438
by: bevanward | last post by:
Hi All I am finding unexpected results when inserted into a newly created table that has a field of datatype int identity (1,1). Basically the order I sort on when inserting into the table is not reflected in the order of the values from the identity field. Have I been wrong in assuming that it should reflect the order from the sort?
3
3981
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I can see that the order I get in my drop event is not always the same as displayed in the explorer window. Further more the order changes depending on how many files/dirs are
54
3916
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of parentheses. 1) "The order of evaluation of subexpressions is determined by the precedence and grouping of operators."
25
2831
by: DanicaDear | last post by:
Hello again Bytes...I missed you! First, background: In a hotstick lab, we ship orders every two years. We ship a new order and the customer uses the new box to return the previous year's order. For example, in November 2007 we shipped an order. November 2009 those sticks expire, and we ship a new order (because customers can't be without sticks) and when they receive the new 2009 order they ship back the old 2007 order. A box number...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.