Answer the question
In order to leave comments, you need to log in
Is it possible to sort with conditions?
Hello!
Is it possible to sort with conditions so that if there is a value equal to A, ASC is sorted, and if B is sorted DESC?
For example something like this:
select Id, Category, Name
from dbo.Products
order by Category, case when Category = 'new' then Id desc else id asc end
Answer the question
In order to leave comments, you need to log in
select Id, Category, Name
from dbo.Products
order by Category, case when Category = 'new' then Id * -1 else id end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question