title: Mysql select query with IF condition in PHP
body: <p>I am writing a mysql query to find sum of two fields based on an id. I have tried writing query with IF condition in select query. Here is my query:</p>
  
  <pre><code>`SELECT (IF(`tax_rate_id`=2,SUM(`net_unit_price`*`quantity`),0)) AS sale5
  
      (IF(`tax_rate_id`=3,SUM(`net_unit_price`*`quantity`),0)) AS sale145
  
      FROM sma_sale_items
  
      where sale_id=4221`
  </code></pre>
  
  <p>I dont know whether my query is right.. If its not possible is there any other way to achieve this? Also I want to do the same query in codeigniter. Can anyone please help me..</p>