MySQL support UPDATE ON DUPLICATE KEY , but to work you need to add a unique constraint to the table you want to insert.
Assuming Table3 is the name of your new table. First you need to add a constraint,
ALTER TABLE Table3 ADD CONSTRAINT tb_uq UNIQUE (name, email)
and now you can have unique records in the new table to combine the previous table,
INSERT INTO table3(name, email) SELECT name, email FROM ( SELECT fid id, fname name, email FROM Table1 UNION ALL SELECT gid id, gname name, gemail email FROM Table1 ) s ON DUPLICATE KEY UPDATE name = VALUES(name);
Alternative solution without using ON DUPLICATE KEY UPDATE . consists in using UNION (without ALL) and assumes Table3.ID is set as auto-increment
INSERT INTO table3(name, email) SELECT name, email FROM ( SELECT fname name, email FROM Table1 UNION SELECT gname name, gemail email FROM Table2 ) s
source share