1

I have data like and it have more columns not only below two:

id | s_type 1 | ACTIVE 2 | PENDING 3 | UPDATE 4 | ACTIVE 5 | PENDING 6 | UPDATE 

I used order by ASC, DESC but i want to display data with custom order and i want to show it as my custom orders (not only asc or descending): want to see first all PENDING then all ACTIVE then all UPDATE s_type

id | s_type 1 | PENDING 2 | PENDING 3 | ACTIVE 4 | ACTIVE 5 | UPDATE 6 | UPDATE 

How can i display with single query

0

2 Answers 2

1

Try this:

SELECT * FROM yourtable ORDER BY field(s_type, 'PENDING', 'ACTIVE', 'UPDATE'), id 

Or use CASE WHEN

SELECT * FROM yourtable ORDER BY CASE s_type WHEN 'PENDING' THEN 1 WHEN 'ACTIVE' THEN 2 WHEN 'UPDATE' THEN 3 END, id 
Sign up to request clarification or add additional context in comments.

Comments

0

i tried this and it works:

 SELECT * FROM mytable ORDER BY s_type = 'UPDATE', signal_status = 'ACTIVE', signal_status = 'PENDING' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.