Order by inside Case in Order By

I have this database

    ID  Title
    1   Unassaign
    6   Prima
    7   Adi

I want to make ID 1 to be display last but the other are sort by their title

Desired results:

    ID  Title
    7   Adi
    6   Prima
    1   Unassaign

This is my code:

SELECT a.ID_WB, a.TITLE, a.DESCRIPTION, a.AUTHOR, a.DATECREATE, a.DATEUPDATE
FROM WORKBOOK a
order by case when ID_WB = 1 then 1
else 0 end

I tried insert Order By after else but it always return SQL error.. Is there a workaroud to this problem? Thanks

PS: The first Order byshould sort by ID

Upvotes: 1

Views: 75

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

Use two expressions in the order by:

order by (case when ID_WB = 1 then 1 else 0 end), title

Upvotes: 3

Related Questions