I have two tables Table1
and Table2
.
Table1
contains records of users and products they have purchased.
Table2
contains a list of the products
mentioned in Table1
with their price
Example of the table explained above:
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:
[{"user":"Jack","sumValue":"4.50"},
{"user":"Jake","sumValue":" 4.00 "},{"user":"Mary","sumValue":" 8.50 "}]
I understand how to create the JSON array but don't understand how the SQL can be written
$sql = " What I am missing ";
if ($result = mysqli_query($con, $sql))