Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

SQL Server - Combine two select queries in sql ?

By M.K. Verma · 4 May 2022

SQL Server - Combine two select queries in sql ?

You could also do it in a single query using a join if UNION doesn't count for "single query":

SELECT s2.* 
  FROM Semester2 s2
       LEFT OUTER JOIN Semester1 s1
         ON s2.StudentId = s1.StudentId
         AND s2.SubjectId = s1.SubjectId
 WHERE s1.StudentId IS NULL;

The WHERE clause will make it so only results where there isn't a perfect match in Semester1 appear.