On 13/02/2011, at 9:40 AM, Andre Polykanine wrote:

> Hi all,
> I'm using in my PHP script the following four MySql queries:
> $q1=mysql_query("SELECT     *    FROM    `CandidateQuestions`    WHERE
> `Category`='1' ORDER BY RAND() LIMIT 1");
> $q2=mysql_query("SELECT     *    FROM    `CandidateQuestions`    WHERE
> `Category`='2' ORDER BY RAND() LIMIT 1");
> $q3=mysql_query("SELECT     *    FROM    `CandidateQuestions`    WHERE
> `Category`='3' ORDER BY RAND() LIMIT 1");
> $q4=mysql_query("SELECT     *    FROM    `CandidateQuestions`    WHERE
> `Category`='4' ORDER BY RAND() LIMIT 1");
> 
> and  here  goes the question: is there a way to make these four in one
> so  strictly  one  random  question  is  selected from all of the four
> categories?
> Thanks!
> 
> -- 
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion

mysql_query('SELECT * FROM `CandidateQuestions` WHERE `Category` IN (1,2,3,4) 
ORDER BY RAND() LIMIT 1;'); should do it.

Though if there's no other possible values for Category, you could just remove 
the WHERE clause.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to