I have the following Table : US_States
Id State
1 CA
2 TX
3 IL
4 MO
5 MI
6 OH
7 CO
8 AZ
9 NY
10 OR
Now I want to display all States in alphabetical order but TX, CA, IL at last. This problem can be solved using FIELD in mysql
FIELD(<FieldName>, Data1, Data2, Data3)
SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL) , State;
If you don't Give State at the end the above states are displayed in Random Order
SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL);
Id State
1 CA
2 TX
3 IL
4 MO
5 MI
6 OH
7 CO
8 AZ
9 NY
10 OR
Now I want to display all States in alphabetical order but TX, CA, IL at last. This problem can be solved using FIELD in mysql
FIELD(<FieldName>, Data1, Data2, Data3)
SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL) , State;
If you don't Give State at the end the above states are displayed in Random Order
SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL);
No comments:
Post a Comment