Mysql – store two tables into a single table in theSQL

MySQL

create table tempA (txt1 int(3))

insert into tempA(txt1) values(25),(null),(77),(44)

create table tempA1 (txt2 int(3))

insert into tempA1 (txt2) values (null),(null),(null),(11),(88)

Can any one suggest me, to insert these two table into a single table(tempA and tempA1) into temp table. But the condition is like the temp table should hold only the values.

Thanks in Advances

Best Answer

If you want to stream changes from tempA and tempA1 to temp, you can use trigger to do this create trigger for both tables

Example:

DELIMITER $$ 
CREATE TRIGGER `insert_to_temp` AFTER INSERT
ON `tempa`
FOR EACH ROW BEGIN
    if new.txt1 is not null THEN
        insert into temp values(new.txt1);
 END IF;
END$$ 
DELIMITER ;

And do this for tempa1

but if you want to do a batch insert you can run:

insert into temp select * from tempa where txt1 is not null union select * from tempa1 where txt2 is not null