Activar
asked on
Help with Query of Queries...I think
I have the following two queries.
<!--- Get all sessions from category --->
<CFQUERY NAME="rsCatSessions" DATASOURCE="DB">
SELECT Quiz, QString
FROM QCat, Quiz
WHERE mcat = '#URL.cat#' AND scat = '#URL.scat#' AND QCat.QID = Quiz.Qstring
ORDER BY Quiz ASC
</CFQUERY>
<!--- Get the passed sessions from the category --->
<CFQUERY NAME="rsTakenPass" DATASOURCE="DB">
SELECT DISTINCT Scores.QString
FROM Scores
WHERE Scores.QString = #rsCatSessions.Qstring# AND username = '#session.username#' AND score >= 90
</CFQUERY>
The first query returns a set of ID's that I match up later with their friendly names. The data may look like:
500
501
502
503
The second query compares what was returned in the first query to the scores table to see what has been passed. The data may look like:
500
501
I need help with a query that will show those items that exist in the first query and NOT in the second. That data would look like:
502
503
Thanks in advance!
<!--- Get all sessions from category --->
<CFQUERY NAME="rsCatSessions" DATASOURCE="DB">
SELECT Quiz, QString
FROM QCat, Quiz
WHERE mcat = '#URL.cat#' AND scat = '#URL.scat#' AND QCat.QID = Quiz.Qstring
ORDER BY Quiz ASC
</CFQUERY>
<!--- Get the passed sessions from the category --->
<CFQUERY NAME="rsTakenPass" DATASOURCE="DB">
SELECT DISTINCT Scores.QString
FROM Scores
WHERE Scores.QString = #rsCatSessions.Qstring# AND username = '#session.username#' AND score >= 90
</CFQUERY>
The first query returns a set of ID's that I match up later with their friendly names. The data may look like:
500
501
502
503
The second query compares what was returned in the first query to the scores table to see what has been passed. The data may look like:
500
501
I need help with a query that will show those items that exist in the first query and NOT in the second. That data would look like:
502
503
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If #passList# is generated by a SELECT statement, then put that statement in where you have #passList#.
This is known as a sub-query.
If you don't actually need #passList# iteslf AND the query works, then you've saved yourself a trip to the server.
This is known as a sub-query.
If you don't actually need #passList# iteslf AND the query works, then you've saved yourself a trip to the server.
ASKER
Thanks for the response. While I did not get the results I was looking for from you solution (no fault of your code, just inadequate SQL experience on my end) it did get me looking in the right direction which was just what I needed.
I ended up storing the values of the second query to a list which I qualified the NOT IN statement against. This seems to work like a charm.
<CFQUERY NAME="rsCatCombined" DATASOURCE="DB">
SELECT Quiz, QString
FROM QCat, Quiz
WHERE
mcat = '#URL.cat#' AND
scat = '#URL.scat#' AND
QCat.QID = Quiz.Qstring AND
QCat.QID NOT IN (#passList#)
ORDER BY QString ASC
</CFQUERY>
Thanks again