limit - Mysql-How to enforce the number of similar records retrieved? -


i working on website shows videos similar of youtube. website has section shows ten similar videos used full text search similar ones.

select * , match (`title` , `description`,`videokey` ) against ('$keywords') score video match (`title` , `description`,`videokey` ) against ('$keywords') limit 10 

the problem retrieves less 10 videos. in case, when there less 10 related videos, there way enforce have 10 videos there not related? if not, possible have 10 select query based on filed such category. how can best , quickest way possible?

not - query needs evaluate conditional against candidate rows before has idea of how many rows returned, hence number of rows returned can't used an argument conditional in query.

you 2 things (well, more, here two):

  • simply perform second query in code, when result rows less 10.
  • grab ten records in second query appended first query via union. http://dev.mysql.com/doc/refman/5.1/en/union.html in code, limit iteration on results hard 10, rather result row size.

i'd go first 1 (a second query). second database query won't kill you, unless you're suffering massive read traffic, in case better solutions involve not hitting database @ if can it.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -