title: How can i use mysql alias column in if statement
body: <p>Unknown column 'CURRENT_STOCK_LEVEL' in 'field list'</p>
  
  <pre><code>$queryString = 'SELECT A.ITEM_CODE, A.BEGINNING_BALANCE AS BEGINNING_BALANCE, B.DELIVERY AS DELIVERY, C.ISSUANCE AS ISSUANCE, 
  (IFNULL(BEGINNING_BALANCE, 0) + IFNULL(DELIVERY, 0)) - IFNULL(ISSUANCE, 0) AS CURRENT_STOCK_LEVEL , A.REORDERPNT AS REORDERPNT,
  
  IF( CURRENT_STOCK_LEVEL &lt;= REORDERPNT, "LOW", "HIGH") AS STATUS
  
  FROM MM_NEW_ROP_ITEMS AS A
  LEFT OUTER JOIN (SELECT ITEM_CODE, SUM(QUANTITY) AS ISSUANCE FROM MM_NEW_ROP_ISSUANCES GROUP BY ITEM_CODE) AS C ON A.ITEM_CODE = C.ITEM_CODE
  LEFT OUTER JOIN (SELECT ITEM_CODE, SUM(QUANTITY) AS DELIVERY FROM MM_NEW_ROP_DELIVERIES GROUP BY ITEM_CODE) AS B ON A.ITEM_CODE = B.ITEM_CODE
  ORDER BY A.ITEM_CODE'; 
  
  $query = mysql_query($queryString) or die(mysql_error());
  
  //makes a loop and creates an array with query fields
  
  $items = array();
  while($item = mysql_fetch_assoc($query)) {
      $items[] = $item;
  }
  
  //encodes for JSON format
  echo json_encode(array(
      "success" =&gt; mysql_errno() == 0,
      "items" =&gt; $items
  ));
  </code></pre>