title: Determine if a field from one table is like the field from another table and if so count occurrence and if less than 3 return the name
body: <p>I have two tables images and Interactions in the same DB.  I want to determine if the image.images which has a png file name for example
  1001_A01_1-4_5mM_3AT_Xgal_7d_W.cropped.resized.grey.png is like plate_name.Interactions which would look like 1001_A01 and then count how many times the images show up.  I should get 3 images if there are fewer than 3 images I would like to have plate_name.Interactions returned.    I would like to do this using 1 query.</p>
  
  <p>So far I have just tried to count how many occurrences there are but this is failing:</p>
  
  <pre><code>select plate_name.Interactions, count(*) as count from Interactions where plate_name.Interactions like image.images;
  </code></pre>
  
  <p>Here are the tables in question:</p>
  
  <pre><code>mysql&gt; desc images;
  +------------+--------------+------+-----+---------+-------+
  | Field      | Type         | Null | Key | Default | Extra |
  +------------+--------------+------+-----+---------+-------+
  | image      | varchar(100) | NO   | MUL | NULL    |       |
  | user_id    | varchar(50)  | YES  |     | NULL    |       |
  | project_id | varchar(50)  | YES  |     | NULL    |       |
  +------------+--------------+------+-----+---------+-------+
  
  mysql&gt; desc Interactions;
  +----------------------+-------------+------+-----+---------+-------+
  | Field                | Type        | Null | Key | Default | Extra |
  +----------------------+-------------+------+-----+---------+-------+
  | plate_name           | varchar(25) | NO   | MUL | NULL    |       |
  | plate_number         | int(11)     | NO   | MUL | NULL    |       |
  | bait_sequence_name   | varchar(25) | NO   |     | NULL    |       |
  | bait_gene_promoter   | varchar(25) | NO   | MUL | NULL    |       |
  | array_coord          | varchar(25) | NO   |     | NULL    |       |
  | transcriptor_factor  | varchar(25) | NO   |     | NULL    |       |
  | orf_name             | varchar(25) | NO   |     | NULL    |       |
  | y_coord              | varchar(25) | NO   | MUL | NULL    |       |
  | x_coord              | varchar(25) | NO   | MUL | NULL    |       |
  | orig_intensity_value | varchar(25) | NO   |     | NULL    |       |
  | rc_intensity_value   | varchar(25) | NO   |     | NULL    |       |
  | ptp_intensity_value  | varchar(25) | NO   |     | NULL    |       |
  | z_score              | varchar(25) | NO   | MUL | NULL    |       |
  | z_prime              | varchar(20) | YES  |     | NULL    |       |
  | call_type            | varchar(25) | NO   |     | NULL    |       |
  | bleed_over           | varchar(25) | NO   | MUL | NULL    |       |
  | plate_median         | int(11)     | YES  | MUL | NULL    |       |
  | bait_gene            | varchar(25) | NO   |     | NULL    |       |
  | bait_prey_orf        | varchar(25) | NO   |     | NULL    |       |
  | human_call           | varchar(25) | NO   |     | NULL    |       |
  | modified_call        | varchar(25) | NO   |     | NULL    |       |
  | duplicate_call       | varchar(25) | YES  |     | NULL    |       |
  | user_id              | varchar(25) | YES  | MUL | NULL    |       |
  | project_id           | varchar(25) | YES  | MUL | NULL    |       |
  +----------------------+-------------+------+-----+---------+-------+
  </code></pre>
  
  <p>Added in response to Bobby's answer:</p>
  
  <pre><code>+----+-------------+--------------+-------+---------------+--------------+---------+---    ---+---------+-----------------------------------------------------------+
  | id | select_type | table        | type  | possible_keys | key          | key_len | ref  | rows    | Extra                                                     |
  +----+-------------+--------------+-------+---------------+--------------+---------+---    ---+---------+-----------------------------------------------------------+
  |  1 | SIMPLE      | images       | index | NULL          | image        | 208     | NULL |   19581 | Using where; Using index; Using temporary; Using filesort |
  |  1 | SIMPLE      | Interactions | range | plate_median  | plate_median | 5       |   NULL | 3714984 | Using where; Using join buffer                            |
  +----+-------------+--------------+-------+---------------+--------------+---------+------+---------+-----------------------------------------------------------+
  </code></pre>