0
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

  • 1
    you mean store only not null values on temp table ? – HamoonDBA Jun 21 '17 at 5:30
  • 1
    Yes, HamoonDBA. – rajesh kannan Jun 21 '17 at 6:03
  • insert into ... select ... where ... is not null. Isn't so hard, isn't it? – tombom Jun 21 '17 at 7:04
  • so mean like this insert into tempA select * from tempA1 where txt1 is not null and txt2 is not null – rajesh kannan Jun 21 '17 at 7:08
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.