Hi!

I have a tests database that has questions (one table is "questions" and a
field in this table is "uid" and another field is "question")
there is also a Testerator table in my tests database, which organizes
questions by section and keeps track of test number (as field "Quid")

SO I would like to obtain a list (with no repeats) of questions that are
found in the questions database, but which are NOT used in a particular
test.
I therefore set up $GlobalUsed which finds all questions which are used
somwhere in a particular test and shoves these into a temporary table, as
such:

$GlobalUsed=MYSQL_QUERY("CREATE TEMPORARY TABLE usedGlobal Select a.Quid,
b.question, b.uid from testerator a, questions b where (a.TestID='$uid') and
(a.Quid=b.uid)");

Next, $Global Unused is established, which finds all questions in the
questions table which are not found in the testerator table for the
particular test in which I am interested.

$GlobalUnused=MYSQL_QUERY("select * from questions, usedGlobal where
questions.uid != usedGlobal.uid ");

HOWEVER, when I use  $row = mysql_fetch_array($GlobalUnused) in a while loop
to display all the unused questions, I get numerous repeats.

I have TWO questions for any gurus willing to share their guru-ness:

1.  Can I do this in such a way as to get a DISTINCT unused question list (I
tried select * DISTINCT in both above statements, to no avail, and I tried
it with DISTINCT and then finished with and ORDER BY clause, but again these
didn't work for me -- I ended up getting no results ).

2.  If I have to use the temporary table (because without sub-selects I'm
not sure how to get the same results) that is fine.   But is there a way to
amalgamate both commands as one select statement and dispense entirely with
the temporary table?

Thanks so much!

-Warren




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to