CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    11

    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?

  2. #2
    Join Date
    Jan 2009
    Posts
    11

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured