title: MySQL IF Statement?
body: <p>I have a big giant sql query where I select and format a bunch of rows for export into Excel. And I want to add one more role, pretty much if the rid (role id) EXISTS and IS 3 then set it to be Role 1 otherwise set it to be Role 2.</p>
  
  <p>Mysql Query Currently</p>
  
  <pre><code>SELECT uc_orders.billing_first_name AS 'First Name', uc_orders.billing_last_name AS 'Last 
  Name', users.name AS 'Username', uc_orders.billing_street1 AS 'Address', 
  uc_orders.billing_city AS 'City', uc_zones.zone_name AS 'State',uc_orders.billing_postal_code
   AS 'Postal Code', ROUND(uc_orders.order_total,2) AS 'Order Total'  FROM uc_orders, users,
   uc_zones WHERE uc_orders.uid!='0' AND uc_orders.uid = users.uid AND uc_orders.billing_zone =
   uc_zones.zone_id AND uc_orders.modified BETWEEN '1271124575' AND '1274978899'
  </code></pre>
  
  <p>HOWEVER the user will not ALWAYS exist in the users_role database (it only exists if it is 3 or some other number, normally it will not exist). So if it does not exist, it would also return 'Role 2';</p>
  
  <p>So</p>
  
  <pre><code>  IF users.uid EXISTS IN users_role.uid THEN
      IF users_role.uid EQUALS users.uid AND users_role.rid = 3
        THEN
          return 'Role 1'
        ELSE
          return 'Role 2';
    ELSE return 'Role 2';
  </code></pre>
  
  <p>How can I do this in MySQL? Or would PHP be the only way?</p>