Reputation: 795
I am trying to run two queries where the second query will run only if the first is not null. Something like:
if((select * from abc where id =1)!=null)
select * from cde
else exit;
what is the proper way to perform such operations?
Upvotes: 0
Views: 353
Reputation: 781
Use exists condition
only if select 1 from abc where id =1
return at least one record select * from cde
will be executed
select * from cde
where exists (select 1 from abc where id =1 )
if you need execute other statements you can use something like follows
if exits (SELECT 1 from abc where id =1) then
-- select a into var_x from cde...
-- upddate ...
else
--
end if;
Upvotes: 2