September 25, 2006 at 9:12 am
Hi all,
I have the following two queries where I need to COUNT values so that I can compare them, but am wondering whether it is possible for me to somehow does this in a single query?
Query 1
SELECT COUNT(*)
FROM tbl_NSP_QuestionTree AS Q
WHERE (Q.ParentUID = 510095)
Query 2
SELECT COUNT(*)
FROM tbl_NSP_QuestionTree AS Q
RIGHT OUTER JOIN tbl_NSP_Answer AS A ON (Q.QuestionTreeUID = A.QuestionTreeUID)
WHERE (Q.ParentUID = 510095)
AND (A.InspectionUID LIKE '00076_0000001481')
I can't really do Sub-Selects apart from using them within the IN clause (SQL Mobile Everywhere )
Thanks in advance.
September 25, 2006 at 9:22 am
Derived table???
You can save the first result into a variable then use the variable in the select... or maybe use a derived table then cross join to the results of the right join!?
September 25, 2006 at 4:09 pm
IF (
SELECT COUNT(Q.QuestionTreeUID ) - COUNT(A.QuestionTreeUID)
FROM tbl_NSP_QuestionTree AS Q
RIGHT OUTER JOIN tbl_NSP_Answer AS A ON (Q.QuestionTreeUID = A.QuestionTreeUID)
WHERE (Q.ParentUID = 510095)
AND (A.InspectionUID LIKE '00076_0000001481')
) <> 0
_____________
Code for TallyGenerator
September 25, 2006 at 7:35 pm
SELECT COUNT(*) AS MainCount,
Sum(CASE WHEN A.InspectionUID LIKE '00076_0000001481'
THEN 1 ELSE 0 END) AS SubCount
FROM tbl_NSP_QuestionTree AS Q LEFT OUTER JOIN
tbl_NSP_Answer AS A ON (Q.QuestionTreeUID = A.QuestionTreeUID)
WHERE (Q.ParentUID = 510095)
-Eddie
Eddie Wuerch
MCM: SQL
September 26, 2006 at 2:22 am
Thanks for the replies guys.
I will try these out, and then get back to you.
Thanks again.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply