title: How to improve an IF statement in MySQL?
body: <p>Consider the mysql </p>
  
  <pre><code>SELECT If(
              (SELECT `price` FROM `prices` AS `B` WHERE `A`.`Item_ID` = `B`.`Item_ID`)&lt;5,
              5,
              (SELECT `price` FROM `prices` AS `B` WHERE `A`.`Item_ID` = `B`.`Item_ID`)
          ) AS `Item_Price' 
  FROM `items` AS `A`
  </code></pre>
  
  <p>where it used to find the price from <code>prices</code> table for each item from the <code>items</code> table, and If the price is less than 5, then it is to 5. The problem with this is that if the <code>IF</code> statement comes false, i.e. the price greater or equal to 5, then it runs another search for the same price which may slow down the page. Is there a way to improve this? </p>