Q:

SQL detect elements in OR clause

i need an sql which whould do somethig as follows:
SELECT col1, col2, cond4 as cond4_is_exclusive
FROM table
WHERE (cond1 AND cond2 AND cond3) OR cond4

Where cond4 = (col3 IN (...))
I NEED cond4_is_exclusive to be TRUE only if condition is met by cond4 itself and not by cond1 and cond2 and cond3 since there is an OR between them.
Is there a such solution?
I need an elegant and optim solution since the query is much larger and there are more conditions  and more complicated.
my current work is like:
SELECT col1, col2, (cond1 AND cond2 AND cond3) as c1, cond4 c2
    FROM table
    WHERE (cond1 AND cond2 AND cond3) OR cond4

And later c2 and c2 are checked with php which is not so elegant

A:

The following should work on Postgres (not sure about MySQL though - I hardly ever use it)
select *
from (
  SELECT col1, col2, 
         (cond1 AND cond2 AND cond3) as c1, 
         cond4 c2
  FROM table
) t
WHERE c1 OR c2

