0

The first table is pre and the second is tran. I want the S_SSN from tran where no and Code of transcript matches with Code and no in pre

4
  • 1
    Can you explain why 811111111 is your expected result Commented Mar 11, 2015 at 3:13
  • The result I get from the Inner query should all be there, if all the requirements match. Then only I should take it. Commented Mar 11, 2015 at 3:19
  • Student 415671238 has D_Code = INFS and C_no = 600 also. Commented Mar 11, 2015 at 3:26
  • @wewesthemenace But that student does not have MATH 321 and INFS 501, as I mentioned Commented Mar 11, 2015 at 3:35

1 Answer 1

1

Is this what you want?

;WITH Cte AS(
    SELECT
        t.Student_SSN,
        cc = COUNT(t.Student_SSN)
    FROM transcript t
    INNER JOIN prereq p
        ON t.C_no = p.P_no
        AND t.D_Code = p.P_Code
    WHERE
        p.D_Code = 'INFS' 
        AND p.C_no = 614
    GROUP BY t.Student_SSN
)
SELECT DISTINCT Student_SSN
FROM Cte
WHERE cc = (SELECT COUNT(*)
            FROM prereq  p
            WHERE p.D_Code = 'INFS' AND p.C_no = 614)
Sign up to request clarification or add additional context in comments.

5 Comments

This does not give me the appropriate results.
Just add the appropriate filter.
The result I get from the Inner query should all be there, if all the requirements match. Then only I should take it.
Yes, I get the result, thanks. But is it possible to get the result without using count ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.