title: Perform inner join filtering defined values
body: <p>Let's say I have the following two tables. What I'm trying to achieve is a search that returns ranked results, when a match is found in <code>A1.pagetitle</code>, <code>A1.content</code> or <code>A2.value</code> - in that order.</p>
  
  <p>But I only need to include results from the second table where the <code>tmplvarid</code> matches specific values (in this case, 15 or 17).</p>
  
  <pre><code> mod_site_content (A1)
   +----+-----------+--------------+
   | id | pagetitle | content      |
   +----+-----------+--------------+
   | 1  | home      | &lt;p&gt; ... &lt;/p&gt; |
   | 2  | project 1 | &lt;p&gt; ... &lt;/p&gt; |
   | 3  | comment 1 | &lt;p&gt; ... &lt;/p&gt; |
   | 4  | project 2 | &lt;p&gt; ... &lt;/p&gt; |
   | 5  | project 3 | &lt;p&gt; ... &lt;/p&gt; |
   | 6  | comment 2 | &lt;p&gt; ... &lt;/p&gt; |
   | etc ...                       |
   +----+-----------+--------------+
  
   mod_site_tmplvar_contentvalues (A2)
   +----+-----------+-----------+-----------------+
   | id | tmplvarid | contentid | value           |
   +----+-----------+-----------+-----------------+
   | 1  | 2         | 1         | [{"key":"val"}] |
   | 2  | 2         | 2         | [{"key":"val"}] |
   | 3  | 5         | 1         | [{"key":"val"}] |
   | 4  | 5         | 5         | [{"key":"val"}] |
   | 5  | 15        | 4         | [{"key":"val"}] |
   | 6  | 15        | 5         | [{"key":"val"}] |
   | etc ...                                      |
   +----+-----------+-----------+-----------------+
  </code></pre>
  
  <p>I think I'm almost there - currently I have:</p>
  
  <pre><code>SELECT DISTINCT A1.pagetitle, A1.content, A1.uri, A2.value,
      CASE
          WHEN A1.pagetitle LIKE ? THEN 1
          WHEN A1.content LIKE ? THEN 2
          WHEN A2.value LIKE ? THEN 3
      END AS rank
  FROM mod_site_content A1
  INNER JOIN mod_site_tmplvar_contentvalues A2
      ON A1.id = A2.contentid
  WHERE pagetitle LIKE ?
      OR content LIKE ?
      OR value LIKE ?
  ORDER BY rank
  </code></pre>
  
  <p>But this includes <em>all</em> corresponding <code>contentid</code>s - I can't for the life of me figure out how to incorporate a condition that only includes certain ones.</p>