Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with order by clause in sql query

Status
Not open for further replies.

ub1234567

Programmer
Dec 4, 2008
69
US
Hi members,

hoep everyone doing excellant.

i am fascing problem in order of sql query data.

suppose my query data of one column is 1
2
3.

using order by ascending or descending clause i can get results of order either 3
2
1 or
1
2
3

but i need order 2
3
1.

so how can i achieve this ?

any help is appreciated.

Thanks.
 
Hi,
May be database dependent but try something like:
Code:
select decode(col1,1,'B',2,'A',3,'C') as OrderBy noprint,col1
order by OrderBy

The idea is to order by a hidden created value that sets up the order you need.





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Does it have to be done in SQL? In Crystal you can group and then specify an order for the group values.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top