I have the following table CandidateInterview :
CandidateID | InterviewID | Status |
---|---|---|
100 | 12 | Not yet |
100 | 13 | In progress |
CREATE TABLE CandidateInterview (CandidateID int, InterviewID int, Status int) INSERT INTO CandidateInterview VALUES (100 , 12 , 1), (100 , 13 , 2), (120 , 9 , 1)
I want to get only the candidates with only with Not Yet status and not other ones
Advertisement
Answer
MS SQL Server 2017 Schema Setup:
CREATE TABLE CandidateInterview (CandidateID int, InterviewID int, Status int) INSERT INTO CandidateInterview VALUES (100 , 12 , 1), (100 , 13 , 2), (120 , 9 , 1)
Query 1:
SELECT * FROM CandidateInterview AS A WHERE NOT EXISTS ( SELECT * FROM CandidateInterview AS B WHERE A.CandidateID=B.CandidateID AND Status >1 )
| CandidateID | InterviewID | Status | |-------------|-------------|--------| | 120 | 9 | 1 |