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

order by for 3 columns

112 100+
hello there,

I have 3 columns which I have to sort.
My data is

-List Item

- Albany 22 194
- Anchorage 24 194
- Canada 38 34
- Carbondale 40 194
- China 51 40
- Des Moines 61 194
- England / UK 307 193
- France 69 66
- Hong Kong 83 84
- Mexico 308 123
- Nashville 119 194
- Russia 310 153
- Singapore 172 165

I want the data to be sorted as

1. Albany 22 194

Anchorage 24 194

Carbondale 40 194

Des Moines 61 194

Nashville 119 194

Canada 38 34

China 51 40

England / UK 307 193

France 69 66

Hong Kong 83 84

Mexico 308 123

Russia 310 153

Singapore 172 165

I tried to use the order by CASE but could not achieve it. can somebody please help me.
thanks in advance.
Dec 16 '09 #1
4 2500
ck9663
2,878 Expert 2GB
What's the category for sorting?


-- CK
Dec 16 '09 #2
user1980
112 100+
the last column has to be in decreasing order and then..first row has to be in alphabetical order..for all the values where column three is not 194, have to be arranged in ascending order.....am I clear?
let me put it in other words, the values of 3rd column have to be sorted as all 194s first and then the rest of them in ascending order....please let me know if i am not clear..
Dec 17 '09 #3
user1980
112 100+
thank you CK for the reply..

i got the desired results using union statement..
Dec 17 '09 #4
ck9663
2,878 Expert 2GB
you can also try

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT....
  3.  
  4. FROM...
  5.  
  6. WHERE...
  7.  
  8. ORDER BY case when COL3 = 194 then 0 else 1 end,  COL1, COL2
  9.  
  10.  
Happy Coding!!!

--- CK
Dec 17 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Laurence Breeze | last post by:
Is it possible to add a column to a table using the "alter table" statement and specify where in the sequence of columns the new column sits. If not is there any way to alter the order of columns...
9
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result...
2
by: AdamM | last post by:
Currently, my code reads from a database without knowing the order of the columns like this: string name = (string)datarow; However, is there a way to write or do an INSERT back to a database...
2
by: dschectman | last post by:
This appears to be a feature of IE JavaScript. I am running IE 6.0 with the latest patches from Microsoft. Are there any workarounds other than re-coding the source HTML to place all the...
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...
2
by: hazz | last post by:
is there a way to have a re-arrangeable list with an asp.net control ? I would like to have a list of database table column values in an ordered list initially loaded by their column order in the...
0
by: todd.freed | last post by:
Hello. I'll make this quick - its quite a conundrum I have the following markup <MyNS:MyControl runat="server" id="myId" CustomProperty1="value" CustomProperty1="value"...
6
by: weetat.yeo | last post by:
Hi all , I have sql statement below , SELECT serial_no,host_name,chasis_model,chasis_flash_size,chasis_dram_size,...
3
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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,...
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...

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.