I have two table say
tbl1
col1 col2
1 xx
2 yy
3 zz
4 dd
and tbl2
col1 col2
1 rr
3 kk
4 ll
now I want to select record from tbl1, if tbl2 doesn't have any record I will select all records from tbl1 otherwise
I will select those records in tbl1 which exist in tbl2 based on col1 of tbl1
I tried it like this, but I am not satisfied with it
select col1, col2
from tbl1
where (
(col1 in (select col1 from tbl2)
or
not exists (select col1 from tbl2)
)
how can I do it in shorter and efficient way
tbl1
col1 col2
1 xx
2 yy
3 zz
4 dd
and tbl2
col1 col2
1 rr
3 kk
4 ll
now I want to select record from tbl1, if tbl2 doesn't have any record I will select all records from tbl1 otherwise
I will select those records in tbl1 which exist in tbl2 based on col1 of tbl1
I tried it like this, but I am not satisfied with it
select col1, col2
from tbl1
where (
(col1 in (select col1 from tbl2)
or
not exists (select col1 from tbl2)
)
how can I do it in shorter and efficient way