sorting the values in a specific order Oracle SQL

I have a table like below. How to sort the column key as F,W,H?

enter image description here

Upvotes: 0

Views: 1411

Answers (3)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

use decode

select a.* from yourtablename a
order by decode(Key,'F',1,'W',2,'H',3)

or

order by instr('FWH',Key)

Upvotes: 0

try this one:

select * from table1 where key in ('F','W','H')
order by case
when key ='F' then 1
when key ='W' then 2
else 3
end;

Upvotes: 1

Fahmi
Fahmi

Reputation: 37473

You can try using case when expression in order by clause

select * from tablename
order by case when key='F' then 1 when key='W' then 2 when key='H' then 3 end

Upvotes: 0

Related Questions