G G wrote:
I have two tables:
Records:
member_id - int
question_id - int
Questions:
id - int
I'm looking to select a random id from the questions table, given that there
is no record of the user already answering that question.
SELECT * FROM `Questions` AS t1 LEFT JOIN `Records` AS t2 ON t1.`id` =
t2.`question_id` AND t2.`member_id`='<memberId>' WHERE t2.`question_id`
IS NULL ORDER BY RAND() LIMIT 1;
The selection of the member_id can also be put in the WHERE clause; this
might be a point of debate. To me it's something that limits the
records considered for the join instead of something that limits the
records in the resulting recordset.
Regards, Jigal.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]