I have a query as follows:
select * from TBL1 inner join TBL2 where tb1.groupkey=tbl2.groupkey
I want to keep these records, however here's the problem, if groupkey is null or ZZ I need to execute the same select with a different table and where condition
select * from TBL1 inner join TBL3 where tb1.groupkey=tbl3.groupkey
Finally if this brings back duplicates I need to set groupkey to null.
I need help designing this query.