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?
 
PortletPaulfreelancerCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.