[英]Insert rows on one table based on the values of a field of another table in PHP-MySQL
[英]PHP-MySQL Query to display rows of one table with priority
我想知道是否有查询(PHP + MySQL代码),因为在我的表中有以下行:
id name featured
----------------
1 Robert 0
2 John 1
3 Pax 1
4 Max 0
5 Emily 0
6 Sara 0
7 Estella 0
在我的页面中显示以下内容(具有特征列值的优先级和ASC的顺序以容纳剩余的):
id name featured
----------------
2 John 1
3 Pax 1
1 Robert 0
4 Max 0
5 Emily 0
6 Sara 0
7 Estella 0
这是我的实际代码:
$sql = "SELECT * FROM employees ORDER BY id desc';
我希望有人帮助我,我在谷歌找不到类似的东西:/
$sql = "SELECT * FROM employees ORDER BY featured desc';
您需要featured
列排序,然后按id
排序
SELECT * FROM employees ORDER BY featured DESC, id ASC
输出:
| id | name | featured |
|----|---------|----------|
| 2 | John | 1 |
| 3 | Pax | 1 |
| 1 | Robert | 0 |
| 4 | Max | 0 |
| 5 | Emily | 0 |
| 6 | Sara | 0 |
| 7 | Estella | 0 |
尝试这个
SELECT * FROM employees ORDER BY featured desc, id asc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.