Mysql
 sql >> Database >  >> RDS >> Mysql

Ricerca booleana fulltext di Mysql:ordina per rilevanza e un altro campo

Puoi fare Left Join per questo e controlla SQLFiddle qui.

SELECT
  p.*,
       MATCH (title) AGAINST ('text' IN BOOLEAN MODE) AS score ,
       COUNT(li.id) AS total_likes 
FROM photos p
  LEFT JOIN likes li
    ON p.id = li.photo_id
     WHERE  MATCH (p.title) AGAINST ('text' IN BOOLEAN MODE) 
    GROUP BY 
      li.photo_id

ORDER BY 
      score , total_likes DESC