How do I favor certain records from an sql query? Such as 50% need to match a certain criteria?
A sample query:
SELECT stock_number, log_date, collection,
MATCH (description, Keywords)
AGAINST ('$query' IN BOOLEAN MODE) AS score
FROM media
WHERE MATCH (description, Keywords)
AGAINST ('$query' IN BOOLEAN MODE)
ORDER BY score, log_date DESC
LIMIT 0, 20
The kicker is that in the result, 50% need to where collection='TEST_1'
Status:
Open Sep 04, 2007 - 12:23 PM
Databases
2answers
Answers
Jan 05, 2009 - 11:19 PM
Sounds like a good question, though it's not totally clear to me what you want to achieve.
It sounds like you want mix some randomness into the result. Randomness is not usually in the nature of SQL, but I suppose the RAND() function could be helpful here.
Another way to get 50% into the mix is to simply select two result sets (with the same number of rows - and none repeated in the two) and put them together with a UNION. In this case you would select the ones with collection="TEST_1" and then the ones with NOT collection="TEST_1".
If you could clarify what you need and if any of this was in the right direction, it would be helpful.
Thanks,
Jakob
Oct 06, 2010 - 02:06 AM
It sounds like you want mix some randomness into the result. Randomness is not usually in the nature of SQL, but I suppose the RAND() function could be helpful here.
http://www.neu92.com/
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment