title: SQL Query, Sort on Substring
body: <p>I wanted to sort results returned from SQL query on the basis of Substring. I am using MYSQL as DB. I am trying to achieve two different results</p>
  
  <pre><code>Sample data
  aaa ad aa
  aaa ab
  aaa ac
  </code></pre>
  
  <p>1) First i want to sort on the basis of second substring.</p>
  
  <pre><code>Result:
  aaa ab
  aaa ac
  aaa ad aa
  </code></pre>
  
  <p>2) Second i want to sort on the basis of last substring.</p>
  
  <pre><code>Result:
  aaa ad aa
  aaa ab
  aaa ac
  </code></pre>
  
  <p>How can i achieve these tasks.</p>
  
  <p>Much appreciate your help..
  Regards</p>
  
  <p>Edit 1: Substrings can be of any length.
  Also for the second case i want sorting on the basis of last substring. Which means it can be on any position.. </p>