title: Trying to write count query loop based on a different table printing
body: <p>I have two tables: </p>
  
  <pre><code>access(name, id, check, key)
  
  events(name, key, event_name)
  </code></pre>
  
  <p>I am trying to print some things from these tables into a php/html table with these columns:</p>
  
  <pre><code>name, key, event_name, access count
  </code></pre>
  
  <p>My trouble being I would like each event to display the "count" of access rows that have the same key.</p>
  
  <p>Event table example:</p>
  
  <pre><code>name  key  event_name
  test  1  first
  joe  2  second
  </code></pre>
  
  <p>And the access table...</p>
  
  <pre><code>name  id  check  key
  test  123  yes  1
  test  1235  yes  1
  joe  175  yes  2
  joe  852  yes  2
  test  5843  yes  1
  test  123455  yes  1
  </code></pre>
  
  <p>The resulting table I am hoping to look like this:</p>
  
  <pre><code>name  key  event_name  access count
  test  1  first  4
  joe  2  second  2
  </code></pre>
  
  <p>Does anybody know how to do this? I've gotten to this but it obviously doesn't work because the key isn't given to the inner select query...</p>
  
  <pre><code>select event_name, name, key, 
         (SELECT COUNT(key) FROM access WHERE key=key AND name=name) 
  from event;
  </code></pre>
  
  <p>Thank you to anyone who takes a look and might have any ideas! I've been staring at this and w3schools for hours</p>