在我当前的方法中,我在sql查询中使用order by date
,然后将back results
设置为新数组,通过php
按ID排序数组。
SELECT * FROM table
WHERE
(
MATCH (title,content)
AGAINST ('+$search' IN BOOLEAN MODE)
)
order by date DESC
limit 0,10
我想问一下,是否有一个sql方法,首先order by date
在这10个结果中得到10个结果,再次order by id
,just in one sql query
?
答案 0 :(得分:10)
围绕当前查询包装外部查询。
SELECT q.*
FROM (SELECT * FROM table
WHERE
(
MATCH (title,content)
AGAINST ('+$search' IN BOOLEAN MODE)
)
order by date DESC
limit 0,10) q
ORDER BY q.id
答案 1 :(得分:0)
这可能有效:
SELECT * FROM (
SELECT * FROM table
WHERE ...
ORDER BY date DESC
LIMIT 10
)
ORDER BY id
答案 2 :(得分:0)
只需输入逗号,然后按另一列排序:
SELECT * FROM table
WHERE
(MATCH (title,content)
AGAINST ('+$search' IN BOOLEAN MODE))
order by date, id DESC
limit 0,10