'MySql: How to show India first and rest of the country ascending order using mysql query?

Suppose the table have 1 column only and have values Canada, London, India, Australia. Now using MYSQL query how to display India 1st and rest of the name after India by ascending order?



Solution 1:[1]

select name from country order by name='India' desc, name;

I think this should work.

Solution 2:[2]

create table #temp ( country nvarchar(25) )

insert into #temp values ('Canada'), ('London'), ('India'), ('Australia')

select * from #temp order by case when country='India' then 1 else 2 end

drop table #temp

Solution 3:[3]

select * from 'table_name' order by (case when name='India' then 0 else 1 end), name asc

If you want to show any two or more countries first then

(case when name='India' then 0 else 1 end)

will be

(case when name='first_country_name' then 0 when name='second_country_name' then 1 else 2 end)

Here you can use negative value as condition.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yasuu
Solution 2 Saranya Jothiprakasam
Solution 3