Issue
i want my query to return a specific row of the table where a column contains specific value first and with year desc.
if i have table something like this
Table employee
id - Name - Year - Status
1 - Ashish - 2016 - Old
2 - Srisan - 2017 - New
3 - Mohit - 2018 - New
4 - Ram - 2015 - Old
5 - Boby - 2016 - New
then result should be
id - Name - Year - Status
3 - Mohit - 2018 - New
2 - Srisan - 2017 - New
5 - Boby - 2016 - New
1 - Ashish - 2016 - Old
4 - Ram - 2015 - Old
Where Status is new and sort via desc of Year
Solution
You can try below -
select * from tablename
order by case when 'New' then 0 else 1 end, year desc
Answered By - Fahmi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.