mysql - combine two tables and add up results -


I have partially the same columns that I want to add to a query:

 < Code> Table 1 | ID | User | Zodiac Date | 1 | 4 | 1000 | 2014-01-01 01:00:00 | 2 | 1 | 2000. 2014-01-01 01:00:00 | 3 | 2 | 1500 | 2014-01-01 01:00:00 Table 2 | ID | User | Zodiac Date | Flag | 1 | 4 | 1000 | 2014-01-01 01:00:00 | 0 | 2 | 3 | 2000. 2014-01-01 01:00:00 | 1 | 3 | 5 | 1500 | 2014-01-01 01:00:00 | 2  

I want to list those content in the tables but I want to add the Amount column. Therefore, if a user is in Table 1 and 2, both times should also be listed 1 time in the result, but the amount must be added.

Therefore the result should be:

  results | User | Zodiac Date | 4 | 2000. 2014-01-01 01:00:00 & lt; - Note that here 2000 (1000 + 1000). 1 | 2000. 2014-01-01 01:00:00 | 2 | 1500 | 2014-01-01 01:00:00 | 3 | 2000. 2014-01-01 01:00:00 5 | 1500 | 2014-01-01 01:00: 00  

I thought about a question

  select from user, amount, date (user selection (Date, date, date, date, 2) T1  

But this amount does not add value and entries listed multiple times if I If I use GROUP BY , it only lists entries 1 time, but the entries are less By programming are, meaning the amount even using the I SUM sum, it only adds all entries and displays 1 entry but I'll take 1 times the amount column amount all entries.

You should use the entire work to group it without any group, just get one line

  SELECT t1.user, SUM (T1.amount), t1.date FROM (Select user, date, date from table 1) Union all (selection user, amount, table) Date from 2) T1 Group by T./user  


Comments