Avatar of CalmSoul
CalmSoul
Flag for United States of America asked on

if and else in select query

I have following oracle table

https://docs.google.com/a/hassanjanjua.com/spreadsheets/d/1O6wJbkiMsEDWASrUA2bNd7biH7KCnOkXGWrvH9MHLxg/edit?usp=sharing

I want to get list of "ID" if "tabl1" = Y but tabl2,tabl3, tabl4,  to tabl5 should be N
I want to get list of "ID" if "tabl2" = Y but tabl1, tabl3, tabl4, tabl5 should be N
I want to get list of "ID" if "tabl3" = Y but tabl1, tabl2, tabl4, tabl5 should be N
I want to get list of "ID" if "tabl4" = Y but tabl1, tabl2, tabl3, tabl5 should be N
I want to get list of "ID" if "tabl5" = Y but tabl1, tabl2, tabl3, tabl4 should be N
Oracle Database

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
slightwv (䄆 Netminder)

I do not understand your requirements.

Can you post the expected results from the provided sample data.
or if what you provided is the results, please provide the data that would get you those results.

What you will likely need is a CASE statement:
select case when some_column = 'Y' then 'X' else 'Z' end from some_table;
Maybe 'AND'ing them:
select case when some_column = 'Y' and another_col='N' then 'X' else 'Z' end from some_table;

But until I understand what you actually want, I cannot provide the specific CASE syntax.
ASKER CERTIFIED SOLUTION
PortletPaul

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy