title: conditional sql query for range of results
body: <p>I have a query that I want to show results differently depending on a specific field.  For example, I am using </p>
  
  <pre><code>$result = $wpdb-&gt;get_results( "SELECT `b`.`company` AS `company`,`bp`.`material` AS `material`,
  if(((`bp`.`cost` * 1.2) &lt; `ls`.`maximumbid`),(ROUND(`bp`.`cost` * 1.2,2)),ROUND(`bp`.`cost`,2)) AS `newcost` 
  from (((`windows_brands_products` `bp` left join `windows_brands` `b` on((`bp`.`brand_id` = `b`.`id`))) 
  join `Windows_last_submissions` `ls`) join `windows_materials` `wm`) 
  where ((`bp`.`width` = round(`ls`.`width`,0)) 
  and (`bp`.`height` = round(`ls`.`height`,0))  
  and (`bp`.`material` = `wm`.`name`) 
  and (`bp`.`type` = `ls`.`type`) 
  and if((`ls`.`minimumbid` &lt;&gt; '0.00'),(`bp`.`cost` between `ls`.`minimumbid` and `ls`.`maximumbid`),(`bp`.`cost` &lt;= `ls`.`maximumbid`))) 
  ORDER BY b.company ASC");
  </code></pre>
  
  <p>The results I want are if the row <code>ls</code>.<code>type</code> = 'Fixed/Picture', I want <code>bp</code>.<code>width</code> = round(<code>ls</code>.<code>width</code>,-1) and still as I have it for any other ls.type</p>
  
  <p>I should be getting correct results from: </p>
  
  <pre><code>select `b`.`company` AS `company`,`bp`.`material` AS `material`,if(((`bp`.`cost` * 1.2) &lt; `ls`.`maximumbid`),round((`bp`.`cost` * 1.2),2),round(`bp`.`cost`,2)) AS `newcost` from (((`windows_brands_products` `bp` left join `windows_brands` `b` on((`bp`.`brand_id` = `b`.`id`))) join `Windows_last_submissions` `ls`) join `windows_materials` `wm`) 
  where if((`ls`.`type` = 'Fixed/Picture'),(`bp`.`width` = round(`ls`.`width`,-2),(`bp`.`width` = round(`ls`.`width`,0)) and (`bp`.`height` = round(`ls`.`height`,0)) and (`bp`.`material` = `wm`.`name`) and (`bp`.`type` = `ls`.`type`) and if((`ls`.`minimumbid` &lt;&gt; '0.00'),(`bp`.`cost` between `ls`.`minimumbid` and `ls`.`maximumbid`),(`bp`.`cost` &lt;= `ls`.`maximumbid`))) order by `b`.`company`
  </code></pre>
  
  <p>but it keeps giving me syntax errors as I try to correct the query which I'm not succeeding.</p>
  
  <p>The point is retrieve a broader range of results if the type is 'Fixed/Picture'</p>
  
  <p>Thank you,
  Casey</p>