我的SQL查询是:SELECT g.name, g.description, g.hash, g.viewsFROM c7_groups g, c7_groups_affiliations ga, c7_groups_categories gcWHERE ga.groups_hash = g.hashAND ga.groups_categories_id = gc.idAND g.groups_categories_id = 611
AND LOWER(ga.name) LIKE LOWER('%$school_name%')
我如何使该查询在每次触发时获取一些随机行。
谢谢
Zeeshan
最佳答案
足够简单,通过RAND()订购:
从c7_groups g,c7_groups_affiliations ga,c7_groups_categories gc WHERE ga.groups_hash = g.hash AND ga.groups_categories_id = gc.id AND g.groups_categories_id =选择g.name,g.description,g.hash,g.views
AND LOWER(ga.name)像LOWER('%$ school_name%')ORDER BY RAND()
有关性能提示,请参见http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
关于mysql - 如何从mysql表中获取随机行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4523158/