ekhodzitsky
ekhodzitsky

Reputation: 153

ORDER BY with two expressions

There is an SQL query with ORDER BY:

ORDER BY someColumn DESC NULLS LAST, NULLIF(anotherColumn->>'someNumField', '')::float';

So, here are two types of sorting. First one is performed, then the second. I want the second sort to be performed under certain conditions. How to do second sorting only if that value is not null?

Upvotes: 0

Views: 117

Answers (1)

Shawn Guillemette
Shawn Guillemette

Reputation: 76

Try using a CASE expression in your order by

ORDER BY someColumn DESC NULLS LAST, CASE when logic then 'a' else 'b' end

Upvotes: 2

Related Questions