To ignore the subquery if the IN clause doesn't retrieve any results, you can use an EXISTS clause. Here's an updated version of the query:
SELECT *
FROM Student
WHERE IsActive = 1
AND EXISTS (SELECT 1 FROM Temp WHERE Temp.stu_Id = Student.stu_Id);
if the subquery inside the EXISTS clause returns no results, the condition will be evaluated as false, and the row won't be included in the final result set.
Left join can also serve this purpose, If you want to ignore the subquery when the IN clause doesn't return any results, you can modify the query using a left join:
SELECT s.*
FROM Student s
LEFT JOIN Temp t
ON s.stu_Id = t.stu_Id
WHERE s.IsActive = 1
AND (t.stu_Id IS NOT NULL OR t.stu_Id IS NULL)