Hi @ron barlow
You don't need to use UNION or Partition, just use 'OR' along with subquery in your WHERE filter clause will be fine.
Please check:
SELECT * FROM @tbl A
WHERE Payment > 0 OR (SELECT COUNT(*) FROM @tbl B WHERE A.StudentID=B.StudentID) = 1
Also, in this case, you could transfer the logic to: any payment > 0 or Max (payment) =0, like this:
SELECT * FROM @tbl A
WHERE Payment > 0 OR (SELECT MAX(Payment) FROM @tbl B WHERE A.StudentID=B.StudentID) = 0
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.