Mysql:将特定记录移到ORDER BY旁边的结果数组顶部 [英] Mysql: move specific records on top of the resultant array beside ORDER BY
本文介绍了Mysql:将特定记录移到ORDER BY旁边的结果数组顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在mysql数据库表中,我有所有类似的国家/地区:
In mysql db table I have all countries like:
我将所有国家/地区作为:
and I fetched all countries as:
SELECT * FROM countries_table ORDER BY country_name
但我想在列表顶部显示一些特定的国家/地区:
but I want to show some specific countries at top of the list:
,然后其他将进入 ORDER BY country_name
是否可以通过 MYSQL 和/或 PHP &怎么样?
Could it be solved by MYSQL and/or PHP & how?
推荐答案
有一个简单但不为人所知的MySQL技巧:
There is a simple and not well-known MySQL trick:
SELECT * FROM countries_table
ORDER BY name = 'Australia' desc,
name = 'UAE' desc,
name = 'Pakistan' desc,
name = 'UK' desc,
name = 'USA' desc,
name asc;
这篇关于Mysql:将特定记录移到ORDER BY旁边的结果数组顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文