title: What is the best practice for the Performance of the Query?
body: <p>On this <a href="http://sqlfiddle.com/#!9/4c36a8/56/0" rel="nofollow noreferrer">Table</a> I use this Script:</p>
  
  <pre><code>$SQL = "
  SELECT id, col
  FROM t
  ORDER BY CASE WHEN 'A B C D E' LIKE CONCAT(col, '%') THEN col END DESC;
  ";
  $stmt = $connect-&gt;prepare($SQL);
  $stmt-&gt;execute();
  if ($stmt-&gt;rowCount &gt; 0) {
      .    .  PULL_DATA  .    .
  } else {
      echo 'No Data Pulled';
  }
  </code></pre>
  
  <p>I used <code>ORDER BY</code> because I wanted to pull the important data first, Which is anything related to col = <code>A B C D E</code> THEN <code>A B C D</code> THEN <code>A B C</code> THEN <code>A B</code> THEN <code>A</code></p>
  
  <p><strong>BUT</strong> If none of those <code>col =</code> values exists, to pull the data that not-related to this set of string, So if col of id <code>1, 2, 7, 5</code> I still get the other records to use, Right now this Query seems not to be possible to Optimize at all, So I thought about the following Script which uses <code>WHERE</code> instead of <code>ORDER BY</code> on the <a href="http://sqlfiddle.com/#!9/4c36a8/62/0" rel="nofollow noreferrer">Query</a>:</p>
  
  <pre><code>$SQL = "
  SELECT id, col
  FROM t
  WHERE 'A B C D E' LIKE CONCAT(col, '%')
  ORDER BY col DESC;
  ";
  $stmt = $connect-&gt;prepare($SQL);
  $stmt-&gt;execute();
  if ($stmt-&gt;rowCount &gt; 0) {
      .    .  PULL_DATA  .    .
  } else {
      $SQL = "
      SELECT id, col
      FROM t
      ORDER BY col DESC;
      ";
      $stmt = $connect-&gt;prepare($SQL);
      $stmt-&gt;execute();
      if ($stmt-&gt;rowCount &gt; 0) {
          .    .  PULL_DATA  .    .
      } else {
          echo 'No Data Pulled';
      }
  }
  </code></pre>
  
  <p>Is this a Good method to maintain performance or is there a better way?</p>
  
  <hr>
  
  <p>To prevent confusion, the <code>A B C D E</code> isn't a <strong>static</strong> string but <strong>variable</strong>,</p>
  
  <p>And it is <strong>not</strong> always letters,</p>
  
  <p>it can be words like <code>Hello My World</code> where the Query orders the values by <code>Hello My World</code> then <code>Hello My</code> then <code>Hello</code> And this Query is built on this <a href="https://dba.stackexchange.com/questions/204323/splitting-a-string-and-order-by-desc-its-matching-values">Question</a></p>