Order by where condition Order by where condition codeigniter codeigniter

Order by where condition


you can use ORDER BY FIELD

SELECT `state`FROM `table1`WHERE `state` IN ('NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah')ORDER BY FIELD(`state`, 'NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah');


SELECT col_nameFROM table_naneWHERE col_nane IN ('NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah')ORDER BY FIELD(`state`, 'NC',.....);

and so on....


try this:

order by case when `state`='NC' or `state`='North Carolina' then 1               when `state`='TN' or `state`='Tennessee' then 2              when `state`='CO' or `state`='Colorado' then 3         end