title: MySQL query order by multiple items not working
body: <p>I´m currently working on a query that must pull up titles ordered by </p>
  
  <ol>
  <li>Exact match,    </li>
  <li>Followed by Highest amount of matched words first,    </li>
  <li>Followed by First word in query is first word in title,</li>
  <li>Followed by Alphabetical order.</li>
  </ol>
  
  <p>Something like this:</p>
  
  <pre><code>SELECT title
  
  FROM title
  
  WHERE title LIKE '%keyword%' OR LIKE '%keyword1%' OR LIKE '%keyword2%'
  
  order by
  
  case when title == 'keyword' then 0 else 1 end asc, 
  
  ((title like '%keyword1%') + (title like '%keyword2%')) desc, 
  
  case when title like 'keyword1%' then 0 else 1 end asc, 
  
  title asc;
  </code></pre>
  
  <p>I tested with 8 titles.</p>
  
  <p>Search: "Buford Christmas".</p>
  
  <p>Result: </p>
  
  <ul>
  <li><p>Buford Christmas</p></li>
  <li><p>Christmas Buford</p></li>
  <li><p>Mr Buford</p></li>
  <li><p>Mr Buford</p></li>
  <li><p>Buford and Lisa</p></li>
  <li><p>Lisa Christmas</p></li>
  <li><p>Me Christmas</p></li>
  <li><p>Me Buford Lisa.</p></li>
  </ul>
  
  <p>I need to find a way to sort the titles so that "Buford and Lisa" should be before "Mr Buford".</p>
  
  <p>They keyword in the query may have any number of sub-keywords, causing the code in the MySQL statement to change dynamically. My example code was generated with a keyword that has 2 sub-keywords. The part that seems not to be working is: "case when title like 'keyword1%' then 0 else 1 end asc" I am wondering if the code is in the wrong position in the comma delimited order sequence or if I should assign different numbers to 'then' and 'else'.</p>
  
  <hr>
  
  <p>About my select code:</p>
  
  <p>In my select statement if the keyword is "Buford Christmas" it's broken into "Buford" and "Christmas" and "Buford Christmas".</p>
  
  <p>About this part of order code: </p>
  
  <pre><code>((title like '%keyword1%') + (title like '%keyword2%')) desc, 
  </code></pre>
  
  <p>MySQL treats boolean expressions as numbers, with true being 1. So, this counts the number of matches.</p>