3

我有这个 SQL 查询。如果我在没有 LIMIT 的情况下运行此查询,则匹配的结果没问题,但是当我使用 limit 运行此查询(以进行无限滚动)时,我无法首先获得最佳匹配,只是获得了 LIMIT 搜索的最佳匹配,而不是在 10 中分隔的整个搜索中的第一个:

    SELECT videos.id_video as idVideo, 1 as idCanal, MATCH (nombre_prog, programas.descrip_larga) AGAINST ('escuela') as relevancia FROM videos
INNER JOIN programas_videos ON videos.id_video = programas_videos.id_video
INNER JOIN programas ON programas_videos.id_prog = programas.id_prog
WHERE MATCH (nombre_prog, programas.descrip_larga) AGAINST ('escuela' IN BOOLEAN MODE)
ORDER BY relevancia DESC LIMIT 5,5

我该如何纠正?

谢谢!

4

1 回答 1

1

尝试这个。它将首先返回子选择的所有结果,然后应用限制。

SELECT  *

FROM 

(
SELECT videos.id_video as idVideo, 1 as idCanal, MATCH (nombre_prog, programas.descrip_larga) AGAINST ('escuela') as relevancia FROM videos
INNER JOIN programas_videos ON videos.id_video = programas_videos.id_video
INNER JOIN programas ON programas_videos.id_prog = programas.id_prog
WHERE MATCH (nombre_prog, programas.descrip_larga) AGAINST ('escuela' IN BOOLEAN MODE)
ORDER BY relevancia DESC 
) AS x

LIMIT 5,5
于 2013-10-14T20:32:27.500 回答