title: SQL query, join multiple tables, Oracle
body: <p>I have an assignment where I need to write a SQL Query that would retrieve the player number and the total amount paid in penalties for players who are captains and have paid more than £80 in total for penalties.</p>
  
  <p>I've got three tables</p>
  
  <p>Players (<strong>playerNo</strong>, name, initials, street, town, postcode)</p>
  
  <p>Teams (<strong>teamNo</strong>, playerNo, division)</p>
  
  <p>Penalties (<strong>paymentNo</strong>, playerNo, penDate, amount)</p>
  
  <p>bold text indicates the primary key. The playerNo in Teams table indicates the team captain.</p>
  
  <p>I don't know how to join three tables. But my attempt at this is:</p>
  
  <pre><code>SELECT p1.playerNo, SUM(p2.amount)
  FROM Players p1 INNER JOIN Teams t
     ON p1.playerNo = t.playerNo 
  JOIN penalties p2
     ON p2.playerNo = p1.playerNo
  GROUP BY playerNo
  HAVING SUM(p2.amount) &gt; 80;
  </code></pre>
  
  <p>Is any of this correct?</p>