0

From this query

SELECT *, 
CASE WHEN STATUS = ONE THEN STATUS 
WHEN STATUS = TWO THEN STATUS 
WHEN ONE = TWO THEN ONE 
ELSE NULL END answer FROM TABLE1

how do i get rows based on the "answer",suppose i want a where condition like, ...where answer='yes', how do i write that sub query

EDIT1:

Sample Table output from the above mentioned query:

|STATUS |ONE    |TWO    |answer
|NO     |NO     |YES    |NO
|YES    |YES    |NO     |YES
|NO     |NO     |NO     |NO

Expected Output with where condition on "answer" (Example, where answer='yes')

|STATUS |ONE    |TWO    |answer
|YES    |YES    |NO     |YES
3

1 Answer 1

0

You didn't post table structure, but based on your sample output I assumed there are 3 columns named status,one and two as demonstrated in SQL Fiddle

If that's the case. Following query may work for you.

SELECT *, 
CASE WHEN status = one THEN status
WHEN status = two THEN status
WHEN one = two THEN one 
ELSE NULL END answer 
FROM `TABLE1` 
HAVING answer='YES';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.