title: How do I sort MySQL search results be relevance?
body: <p>I'm using PDO to search a MySQL table for search results. My query looks like this</p>
  
  <pre><code>$sql = "SELECT * FROM users WHERE username LIKE :username OR name LIKE :name ORDER BY uniqueid DESC LIMIT 6";
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;bindValue(':username', '%'.$query.'%');
  $stmt-&gt;bindValue(':name', $query.'%');
  </code></pre>
  
  <p>What I'm trying to accomplish is that in my results array, the results that match like this:</p>
  
  <pre><code>$query.'%'
  </code></pre>
  
  <p>Should appear before results that match like this:</p>
  
  <pre><code>'%'.$query.'%'
  </code></pre>
  
  <p>Is there a way to sort results by such relevance without two queries, preferably in pure SQL? </p>