0

Let's say I have this in a column:

'a'
'b'
'c'
'd'
'e'

I want the data to be sorted and looked like this:

'a'
'b'
'd'
'e'
'c'

Is this possible?

3
  • Add a new column with order number which generating by your rules. No other method. Commented Sep 14, 2018 at 2:50
  • What is the logic for this ordering? See the above comment as well. Commented Sep 14, 2018 at 2:55
  • I have some data where for nothing other than cosmetic purposes, I wanted one particular row above every other row, that was it. Commented Sep 14, 2018 at 3:21

2 Answers 2

2
select letter
from letters
order by
   case letter
     when 'a' then 0
     when 'b' then 1
     when 'd' then 2
     when 'e' then 3
     when 'c' then 4
   end
Sign up to request clarification or add additional context in comments.

1 Comment

This is just the ans from stackoverflow.com/questions/19196475/….
2

An other way around using CASE statement is,

Query

select [column_name] 
from [your_table_name]
order by 
  case [column_name] 
  when 'c' then 2 
  else 1 end, 
[column_name];

Find a demo here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.