title: DB machine CPU cycles Vs mid-tier machine CPU cycles
body: <p>I have a SELECT query with lot of IF conditions, which I can do either in the query itself (takes DB machine's CPU) or I can put it in my java code (takes server machine's CPU).</p>
  
  <p>Is there any preferred approach here (to put conditions in DB Vs in mid-tier)?</p>
  
  <p><strong>UPDATE</strong>: My query is a join on more than 2 tables,
  and I am using left join to combine and there are some rows which will have corresponding row in 2nd table and some are not.
  I need to have some default value for those columns when I don't have corresponding row in 2nd table.</p>
  
  <pre><code>SElECT CASE WHEN t2.col1 is null
      then 'default' else t2.col1
      END
  FROM table1 t1
  LEFT JOIN table2 t2 ON t1.id = t2.id
  </code></pre>