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
LVL 5
CalmSoulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
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.
0
PortletPaulEE Topic AdvisorCommented:
Individually:
select ID
from your_table
where tabl1 = 'Y' and tabl2 = 'N' and tabl3 = 'N' and  tabl4= 'N' and tabl5 = 'N'
;

select ID
from your_table
where tabl2 = 'Y' and tabl1 = 'N' and tabl3 = 'N' and  tabl4= 'N' and tabl5 = 'N'
;

select ID
from your_table
where tabl3 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl4= 'N' and tabl5 = 'N'
;

select ID
from your_table
where tabl4 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl3= 'N' and tabl5 = 'N'
;

select ID
from your_table
where tabl5 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl3= 'N' and tabl4 = 'N'
;

Together:
select ID
from your_table
where ( tabl1 = 'Y' and tabl2 = 'N' and tabl3 = 'N' and  tabl4= 'N' and tabl5 = 'N' )
       or ( tabl2 = 'Y' and tabl1 = 'N' and tabl3 = 'N' and  tabl4= 'N' and tabl5 = 'N' )
       or ( tabl3 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl4= 'N' and tabl5 = 'N' )
       or ( tabl4 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl3= 'N' and tabl5 = 'N' )
       or ( tabl5 = 'Y' and tabl1 = 'N' and tabl2 = 'N' and  tabl3= 'N' and tabl4 = 'N' )
;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.