Is it possible to retrieve in output which predicate in where clause is evaluated true?
<p>Is it possibile in a select query that has a where clause with a lot of predicates retrieving in output which one predicate is evaluated true, together with real tuple?</p>

<p>For instance, given this table:</p>

<pre><code>Table person
name        age         hair_color
Tom         12          Brown
Bob         27          Black
Sam         20          Red
Ann         15          Blonde
John        30          Blonde
</code></pre>

<p>An that query:</p>

<pre><code>select *
from person
where (age &gt;= 25) or (hair_color = 'Blonde')
</code></pre>

<p>I would like to have in output something like that:</p>

<pre><code>name        age         hair_color      clause_1        clause_2
Bob         27          Black           true            false
Ann         15          Blonde          false           true
John        30          Blonde          true            true
</code></pre>

<p>What do you suggest to achieve a similar result?</p>

<p><strong>UPDATE</strong></p>

<p>Thanks! You answered my question! So It's possible with something like that:</p>

<pre><code>select *
from (
    select p.*, 
        (age &gt;= 25) as clause_1, 
        (hair_color = 'Blonde') as clause_2
    from test.person as p
) as t
where t.clause_1 or t.clause_2
</code></pre>

<p>Now I have a related one. If I already have a table predisposed to contain this clause evaluations, for instance 'check_1' and 'check_2'.</p>

<pre><code>Table person
name        age         hair_color      check_1     check_2
Tom         12          Brown
Bob         27          Black
Sam         20          Red
Ann         15          Blonde
John        30          Blonde
</code></pre>

<p>Is there any way to 'temporary' valorize this field during the select query (check_1 = clause_1, check_2 = clause_2)?</p>

<pre><code>name        age         hair_color      check_1     check_2
Bob         27          Black           true        false
Ann         15          Blonde          false       true
John        30          Blonde          true        true
</code></pre>

<p>I ask you because I need it in a Java project in which I use JPA and Criteria API to make typed query, and I would like to get the object 'Person' with 'check' values evaluated in one shot.</p>

<p>Thanks again everyone!</p>