title: SQL ORDER BY for two conditions
body: <p>I've tried to resolve this problem more than two hours. I need your help. I want to sort data from two tables by using this query:</p>
  
  <pre><code>SELECT *
  FROM (
  
  SELECT INV.`id` , INV.`userid` , Cli.firstname, Cli.lastname,   Cli.companyname, Cli.currency, INV.`total` , INV.`date` , INV.`duedate`
  FROM tblinvoices AS INV, tblclients Cli
  WHERE now( ) &gt;= DATE_ADD( INV.duedate, INTERVAL +2
  DAY )
  AND INV.STATUS = 'unpaid'
  AND Cli.id = INV.userid
  AND INV.total &gt;=200
  AND INV.`date` != INV.`duedate`
  ) AS X
  ORDER BY X.duedate ASC
  </code></pre>
  
  <p>I get this result :</p>
  
  <pre><code>id  userid firstname    lastname    companyname     currency    total   date    duedate 
  3   3   younes  Abakarim        1   154877.00   2014-10-18  2014-11-01
  9   12  Faissal Marouan 1   2568.00     2014-10-23  2014-11-06
  34  3   younes  Abakarim        1   252.60  2015-01-10  2015-01-15
  31  12  Faissal Marouan 1   288.00  2015-01-01  2015-01-15
  36  3   younes  Abakarim    Bestgallery 1   288.00  2015-01-16  2015-01-19
  </code></pre>
  
  <p>But what I want is this: </p>
  
  <pre><code>id  userid  firstname   lastname    companyname     currency    total   date    duedate 
  3   3   younes  Abakarim        1   154877.00   2014-10-18  2014-11-01
  34  3   younes  Abakarim        1   252.60  2015-01-10  2015-01-15
  36  3   younes  Abakarim    Bestgallery 1   288.00  2015-01-16  2015-01-19
  9   12  Faissal Marouan 1   2568.00     2014-10-23  2014-11-06
  31  12  Faissal Marouan 1   288.00  2015-01-01  2015-01-15
  </code></pre>
  
  <p>And still sorted by <code>duedate</code>.</p>