mysql - Ordering the results based on the where condition -


suppose table1 has 3 attributes: first_name, last_name, , country. example following tuples:

john white canada john smith france mary smith canada ben  smith canada mary black usa     

i looking first name, "john", or last name "smith", or country "us":

select * table1     first_name='john' or     last_name='smith' or     country='us' 

i want result in following order: first first name, john, last name smith, , last country us

i know can write following 3 different queries , use output in order want:

select * table1 first_name='john'  select * table1 last_name='smith'  select * table1 country='us' 

i looking better way.

question1: if use mentioned 3 queries , find union order change, right? if yes, how can append results?

question2: there better way?

your order should like

order case            when first_name = 'john' 1            when last_name = 'smith' 2            else 3          end 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -