title: mysql ORDER BY IF ELSE
body: <p>I was thinking if there is some more advanced way to use <code>ORDER BY</code> in mysql query.</p>
  
  <p>I have query to get products from db, using order by price.
  The problem is  if discount value not null, it overrides the main price, and it should somehow
  override the <code>ORDER BY</code> line.</p>
  
  <p><strong>IDEA:</strong></p>
  
  <pre><code>DESC
  
  product_price discount
  900           0
  800           0
  1200          700 //dicount overrides price
  600           0
  </code></pre>
  
  <p><br />
  <br />
  The query got 25 lines, but the logic is something like this:</p>
  
  <pre><code>SELECT
  product_price as price,
  IFNULL(discount_amount,0) as discount
  
  FROM not_relevant
  
  WHERE not_relevant
  
  ORDER BY product_price DESC
  </code></pre>
  
  <p>So when i write products to category sort by price, certain products have discount so the main price is overwritten and sort only by price is not accurate.</p>
  
  <p>I tried to use <code>coalesce</code>, or two <code>ORDER BY</code>. </p>
  
  <p>Any ideas?
  Thanks for help.</p>