Skip to content
Advertisement

how to sum two columns from different tables MySQL

I need to sum the data from two different columns located in different tables and grouped by session_id…..

FIRST TABLE

second table

I need to sum the column of spent_points + price_points grouped by session_id

this is the result i hope to get

this is the result i hope to get

I have tried with this query but I have only managed to group the data but I have not been able to sum it by session_id

Advertisement

Answer

First use UNION ALL to get all the rows from the 2 tables that you want and then aggregate:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement