title: can't make the sum of columns in 2 connected tables using MySQL
body: <p>I am quit new to MySQL.</p>
  
  <p>I have 2 tables:</p>
  
  <p><strong>Table 1: client_debts (<em>id</em>, client_name, total_debts)</strong></p>
  
  <p><strong>Table 2: client_details (<em>id</em>, <em>client_id</em>, payments)</strong></p>
  
  <p>Where client_id is the foreign key of table 2 and is connected to table 1 id column.</p>
  
  <p>What I need to do is, to create an PHP-HTML <strong><em>(No problem with this part)</em></strong> table that gives me the total debts of a client, with the total of his payments to compare how much he still have. IF his payments are equal, I want to remove his name from the HTML table.</p>
  
  <p><strong>What I tried ?</strong></p>
  
  <p>I tried this SQL query:</p>
  
  <pre><code>    SELECT (SELECT sum(total_debts) FROM client_debts) AS 'TOTAL', 
      (SELECT sum(payments) FROM client_details) AS 'Total Payed' 
      FROM client_debts INNER JOIN client_details 
      ON client_debts.id = client_details.client_id
  </code></pre>
  
  <p>And I have got this:</p>
  
  <p><a href="https://i.stack.imgur.com/xlzNU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xlzNU.jpg" alt="enter image description here"></a></p>
  
  <p>And the results are only for the first id and it is duplicated to all rows.</p>
  
  <p>So how can I do this for every client?</p>