Link to home
Start Free TrialLog in
Avatar of Larry Groves
Larry GrovesFlag for United States of America

asked on

Oracle subquery that is only valid if 1 row exists

I'm trying to run a subquery that will only be valid if only 1 row exists in my subquery.

For example:
select o.*
from orders o
where o.a = 'a'
and o.c = 1
and exists (select a.a
from address a
where o.a = a.a
and only 1 row exists)

If I'm supposed to use a "having (a) = 1" I really don't know the syntax for it in a subquery.

Also, I know I could use a proc to easily solve this but unfortunately I don't have access to implement that so I need to do it in a SQL statement. If it's even possible, that is.

Would a case statement work for this?

Please note that I'm working on Oracle 12c if that helps any.

Thanks,
Larry
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Groves

ASKER

Thanks Sharath. This worked perfectly! I appreciate your help.

Thanks,
Larry