开发者

How do I select a bunch of random rows from a table?

I have a database of filenames that relate many-to-one to a set of subjects. How can I randomly select one filename from the several in the database that relate to a given subject?

I'm working with Zend Framework, so if ther开发者_开发问答e is a ZF function that would help please mention it.


There's probably a more efficient way, but i've used a mysql query like this before. (Never messed with ZF, so i do it the mysql way...)

SELECT fn.filename
FROM subjects s
INNER JOIN filenames fn ON whatever joins the tables
WHERE the subject id matches
ORDER BY RAND()
LIMIT 1


select filename from FileSubjects where subject = "subject" order by rand() limit 1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜