GordonPrince
asked on
return Y or N based on result of EXISTS subquery
What would be a good way to make this logic work in a SQL query?
select col1, col2, col3, YorN
from tab1
I want to return YorN as either a literal 'Y' or 'N' based on whether or not something EXISTS or not.
if EXISTS (select 1 from tab2 where tab1.col1 = tab2.col1) then Y
if NOT EXISTS (same as above) then select N
What's the most efficient way of doing this?
select col1, col2, col3, YorN
from tab1
I want to return YorN as either a literal 'Y' or 'N' based on whether or not something EXISTS or not.
if EXISTS (select 1 from tab2 where tab1.col1 = tab2.col1) then Y
if NOT EXISTS (same as above) then select N
What's the most efficient way of doing this?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Lee
Open in new window