Here is the table structure (one to many relation). Each group (T01,T02,T03...) will either have a stamp Number or No Stamp number

![enter image description here](https://i.stack.imgur.com/j2d7D.jpg)

I would like to filter rows from the result set given in figure 1 based on DocType and StampNum field. I want to show all the rows apart from those rows which have docType 4 and StampNum is Null. If there is a StampNum with docType 4 then it should be included.

So result would look like

![enter image description here](https://i.stack.imgur.com/AZDeU.jpg)
I have tried the following sql but its not showing right results.

```
SELECT * FROM EmpDocs a
WHERE NOT EXISTS ( select * from EmpDocs b 
        where a.ID = b.ID 
          and b.DocType = 4 and b.StampNum is not null) 

```