Reputation: 19885
My Sql query is :
SELECT g.name, g.description, g.hash, g.views
FROM 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 = 611
AND LOWER(ga.name) LIKE LOWER('%$school_name%')
How can i make this query to fetch some Random row every-time it is fired.
Thanks Zeeshan
Upvotes: 0
Views: 83
Reputation: 4431
Easy enough, ORDER BY RAND():
SELECT g.name, g.description, g.hash, g.views FROM 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 = 611 AND LOWER(ga.name) LIKE LOWER('%$school_name%') ORDER BY RAND()
See http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html for performance tips
Upvotes: 2
Reputation: 8989
SELECT g.name, g.description, g.hash, g.views FROM 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 = 611
AND LOWER(ga.name) LIKE LOWER('%$school_name%') ORDER BY RAND();
However this is a pretty terrible idea.
Upvotes: 0