Lets say, just for example I have 10 records in a database table which has the fields name and count... The content of the count field is a numeric value where each record is different... Now what I want to do is to select a random record from this database but the higher the count value is the more chance they have of being displayed... For example if the 1st record had count of 1000 and 8th record had count of 100 - then it was run 10 times.. i would expect the majority to be the 1st record but not all... So basically Im adding more weight to the higher number... How can I do this? Thanks
Obviously, don't select * unless you absolutely need every column returned. But this might work. You can also remove the limit 0,1 if you want to return more than one record. The higher the count the more weighted the row is, the more often it should show up. select * from tbl_mytable order by rand()*(1/count) limit 0,1 Code (markup):