user1989
user1989

Reputation: 217

SQL sub query in SQL Server

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

Upvotes: 0

Views: 38

Answers (1)

Felix Pamittan
Felix Pamittan

Reputation: 31879

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)

Upvotes: 1

Related Questions