title: How can two tables be joined together to create a JSON | PHP
body: <p>I have two tables <code>Table1</code> and <code>Table2</code>.</p>
  
  <p><code>Table1</code> contains records of users and products they have purchased.</p>
  
  <p><code>Table2</code> contains a list of the <code>products</code> mentioned in <code>Table1</code> with their <code>price</code></p>
  
  <p><strong>Example of the table explained above:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/ySkQj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySkQj.png" alt="tables"></a></p>
  
  <p>I would like to join these two tables in a query that takes the sum of all the sum value of all the purchases made by each user and display that than create a JSON that looks like this:</p>
  
  <pre><code>[{"user":"Jack","sumValue":"4.50"},
  {"user":"Jake","sumValue":" 4.00 "},{"user":"Mary","sumValue":" 8.50 "}]
  </code></pre>
  
  <p>I understand how to create the JSON array but don't understand how the SQL can be written</p>
  
  <pre><code>$sql =  "      What I am missing                  ";
  
  if ($result = mysqli_query($con, $sql))
  </code></pre>