I have 3 mysql tables. All the tables will have many entries of the same person.
For desire output need help
Table_1 Table_2 Table_3
id name bill id name total id name total
1 John 100 1 John 20 1 John 100
2 Kevin 50 2 Tom 30 2 Tom 20
3 Tom 50 3 Tom 30
4 John 20
Output_Table
name sum(bill) sum(total) sum(amount)
John 120 20 100
Kevin 50 null null
Tom 50 30 50
2
Answers
Solution could be as below query
This is the test I did in dbfiddle.uk. I think we can’t determine which table contains all the names, for example, table_1 has Kevin, other tables don’t, table_2 has Peter, other tables don’t, so we need to look up all the names jointly, and then sum the data according to the name.
My sql looks bloated and complicated, but I hope it helps.