mysql按某字段排序查询时,怎么样始终把某条记录放在第一个呢?
mysql按某字段排序查询时,怎么样始终把某条记录放在第一个呢?
mysql按某字段排序查询时,怎么样始终把某条记录放在第一个呢?
$sql = "SELECT t.*, f.name FROM threads t, forums f where f.fid=t.fid ORDER BY id=10000 desc , t.dateline DESC LIMIT 0, 10";
但效率比较差。
下面这个效率上会好一些
1
2
3
4
5
6
|
select * from (
( SELECT t.*, f. name FROM threads t, forums f where f.fid=t.fid id=10000)
union all
( SELECT t.*, f. name FROM threads t, forums f ORDER BY t.dateline DESC LIMIT 0, 10)
) t
order by id=10000 desc ,datelineDESC LIMIT 0, 10
|
这是网上的一个例子,应该不用我多做介绍,现在我写一下我的,其实功能实现都可以的