I have seen this great answer on how to select a random row from a table and it works great on my table. Modifying that query I ended up with:
SELECT r1.clID, clUserName, clCompanyName, clBio
FROM customerlogin AS r1 JOIN
(
SELECT
(
RAND() *
(
SELECT MAX(clID)
FROM customerlogin))
AS clID)
AS r2
WHERE r1.clID >= r2.clID
ORDER BY r1.clID ASC LIMIT 1
However I need to go one step further and limit the possible answers to those that match certain criteria.
I think the best way to do this would to be to build a temporary table, selecting only the valid rows from the original table, and then select a random row from the temporary table, however I am unsure on how to go about doing this. I've tried googling various combinations of create and select from random table, but with no joy so far. I'm assuming I just don't know the right way to ask what I'm after.
Can anybody please point me to a guide or some example code on how this can be accomplished? Or if there is a better solution I am overlooking then I am open to suggestions.