By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tbl1 (code int, sal_month varchar(10))
insert into tbl1 values(101,'2/2017'),(102,'2/2017'),(103,'2/2017'),(104,'2/2017'),
(101,'3/2017'),(102,'3/2017'),(104,'3/2017'),(101,'4/2017'),(103,'4/2017')
9 rows affected
Select c.code, m.sal_month
From ( select distinct sal_month from tbl1 ) m
Cross join ( select distinct code from tbl1 ) c
Left join tbl1 t on m.sal_month = t.sal_month
And c.code = t.code
Where t.sal_month IS NULL
code | sal_month |
---|---|
103 | 3/2017 |
102 | 4/2017 |
104 | 4/2017 |