I have a problem that I need help with. I have a MySQL table with name, address, email, and quantity. In this table there are multiple rows where the name, address, and email are the same but the quantity may vary. I need to make a table with the unique name, address, and emails but have the total sum of the quantity for each of those unique name, address, emails. For instance if I have a table with;
Fred, 123rd St, fred@fred.org, 4
Fred, 123rd St, fred@fred.org, 3
Fred, 123rd St, fred@fred.org, 1
George, 489 S. St., george@george.com, 5
George, 489 S. St., george@george.com, 4
George, 489 S. St., george@george.com, 2
I need it to be in one table;
Fred, 123rd St, fred@fred.org, 8
George, 489 S. St., george@george.com, 11
I know how to move the distinct name, address, and email into another table. I just don't know how to add up the sum of the quantity for each unique name, address, and email and insert that into the other table.
I used
INSERT INTO tbl2 (name, address, email) SELECT DISTINCT name, address, email from tbl1;
to remove the duplicates. Can anyone give me an idea to help me add up the sums and insert in to the new table?
Your help would be greatly appreciated.