Reply to select rand() from top 10

Your name:

Reply:


Posted by Gordan on 10/28/06 12:36

hi all,

I need to select a random row from the "top 10" rows ordered by some key. Ie
there's a table with people and they have some points ...... I don't want to say
"the person with the most point is Gregor" I want "One of the top people is
Gregor" because he is one of the top 10 but amongst those I want a random row.
I had no trouble writing the query, but its slooooooooooooooooow so I need some
help in optimising it. Here's the query

SELECT query FROM (SELECT query, count(query) as count FROM search_history WHERE
module = 'tags'
GROUP BY query ORDER BY count DESC LIMIT 0, 10) as queries ORDER BY RAND() LIMIT
0, 1

tbl struct
CREATE TABLE search_history (
id int(11) NOT NULL auto_increment,
`query` varchar(255) NOT NULL default '',
username varchar(255) NOT NULL default '',
referer varchar(255) NOT NULL default '',
module varchar(255) NOT NULL default '',
`timestamp` varchar(10) NOT NULL default '',
PRIMARY KEY (id),
KEY `query` (`query`),
KEY module (module)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;thanks!Gordan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация