Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql LIMIT using MATCH AGAINST

I have this SQL query. If I run this query without the LIMIT, the result of the match it's OK, but when I run this with limit (to make an infinite scroll), i cannot get the best match first, just I get the best match of the LIMIT search, not the first of the entire search separated in 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

How can I correct this?

Thank you!

like image 970
Martin Avatar asked Feb 03 '26 06:02

Martin


1 Answers

Try this. It will return all of the results of the sub-select first and then apply the limit.

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
like image 121
Tom Avatar answered Feb 04 '26 21:02

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!