Matching Query Results inside another Query Results

• December 9th, 2012, 01:18 AM
jd53887
Matching Query Results inside another Query Results
TableA(AID,A1)
TableB(BID, AID)

SELECT AID FROM TABLEA WHERE A1 = 1;

SELECT B.BID, A.AID FROM AID A, BID B WHERE A.AID = B.BID AND A1 = 1;

The first code above will give a list. (Ex. 1,2,3,6) I need to know if any BID have an AID list that at least have all the results of AID from the first code (Ex. 1, 2, 3, 4, 5, 6 GOOD) (Ex. 1, 2, 3, 5 BAD)

Basically, each AID is either positive or negative for A1. Each BID is either positive or negative with each AID. I need to know which BID is positive for ALL of "the positive AID."

Any suggestions?
• December 9th, 2012, 12:34 PM
jd53887
Re: Matching Query Results inside another Query Results
I solved it. All I need was a night of sleep and breakfast.

Code:
SELECT B.BID
FROM TableA A, TableB B
WHERE A.AID = B.BID AND A.A1 = 1
HAVING COUNT(B.AID) = (
SELECT FROM COUNT(A.AID)
FROM AID A
WHERE A.A1 = 1)
GROUP BY B.BID
ORDER BY B.BID
;

Explanation: I got the total count of Horror films that exists. I compared the User's count of horror filmed they watched to that number. If any user has the same count, they show up.