I need something like:
select * from table1 where {if PKID = MasterPKID - (that PKID should not be present as refNo in table2)}. ie- 652 should not be present in Table2
I am totally clueless.
Can we achieve it in one query?
Use Not exists
select * from table1 a where PKID = MasterPKID and not exists (select 1 from table2 b where a.PKID = b.refno) Try any of these!!
If MaterPKID can contain NULL Values then go for not exists
select * from table1 a where PKID = MasterPKID and not exists (select 1 from table2 b where a.PKID = b.refno) else go with not in
select * from table1 a where PKID = MasterPKID and PKID not in (select REFNO from table2)
if PKID = MasterPKID - (that PKID should not be present as refNo in table2). What do you mean by that. Please give appropriate example with some more data.