Today I came to know that we can use CASE with ORDER BY clause. Its a nice functionality which helps you to avoid UNIOUN when you have to display the records in some specific order and still you need to sort them.
As shown below I have created an Employee table with ID (Primary key),Name, Address and Phone columns.
Fig - (1) Employee table.
I have also inserted some temporary data as shown below,
Fig - (2) Insert Statements
Now consider that have to display the records of employee table order by Address however you want first it should display all the records with USA in address field then Ahmedabad then Gujarat and after that all. Here is the output that we want,
Fig - (3) Result
Below is the query that displays the result as shown in fig - (3),
Happy Programming !!!