Sometimes you need to show a specific row first then follow remaining rows in mysql database. For example, I want to show list of countries but a country name like Australia on top then other countries.
I am going to show you.
Suppose mysql table is "country" and query used to retrieve country information is :
Output:
If you want to show Australia on top of the row. Use following script
I am going to show you.
Suppose mysql table is "country" and query used to retrieve country information is :
"SELECT * FROM country ORDER BY country_id ASC"
Output:
If you want to show Australia on top of the row. Use following script
SELECT *, IF(country_code = 'AU', 1, 0) AS uses_default
FROM country
ORDER BY uses_default DESC, country_id ASC
I am taking example of Australia, But you can put any country name on top. If you have any question, you can comment here. I will try to give you response as soon as possible.