title: Mysql - Order results by number of Id´s in another table
body: <p>I have problem with my ordering of results in search.</p>
  
  <p>I have two tables</p>
  
  <p>Table photos (first table) where I have information about photos and every photo has ID.</p>
  
  <p>When somebody clicks on result (photo) script saves information about it to second table.
  Table (second table) looks like this</p>
  
  <pre><code>______________________
  |ID of photo| keyword|
  </code></pre>
  
  <p>And sort results by count of photo IDs in second table</p>
  
  <p>so <code>order by (something) + (something) + (count id´s of photo for phrase by user (keyword))</code></p>
  
  <p>For example:</p>
  
  <p>In table are:</p>
  
  <pre><code>|id|keyword|
  |5 |car    |
  |5 |car    |
  |6 |car    |
  |6 |car    |
  |2 |car    | 
  |5 |car    |
  </code></pre>
  
  <p>Search query:
  <br><pre>SELECT * FROM <code>bx_photos_main</code> WHERE (<code>Title</code> LIKE '%keyword%') OR (<code>Desc</code> LIKE '%keyword%') OR (<code>Categories</code> LIKE '%keyword%')order by (order) DESC LIMIT 0, 10;</pre></p>
  
  <p>When anyone try find "car" Photo 5 will be first, 6 second and third will be photo with id 2...Can somebody help me? </p>
  
  <p>Structure
  bx_photos_main<br>
  <code>
  ID  &nbsp;-&nbsp;   int(10) &nbsp;-&nbsp;   UNSIGNED &nbsp;-&nbsp;  AUTO_INCREMENT</code></p>
  
  <p>_bx_hledej (seccond table)<br>
  <code>id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;int(11)<br>
  keyword&nbsp;-&nbsp;varchar(20)</code></p>