Home > front end >  How to loop over records and then search into another table and if not found then insert it after fe
How to loop over records and then search into another table and if not found then insert it after fe

Time:05-26

I have 3 tables in my data base
Table 1 Table 2 Table 3

I need to take each id from table1 and need to look in table2 if it is present then do nothing other wise for that Id I need to look into table3 if i am able to find it then fetch the phone number and along with the details from table 1 insert it into table2 .How to do this in oracle ?

CodePudding user response:

You can try this:

db<>fiddle

INSERT INTO table_2
SELECT table_1.id, table_1.name, table_1.gender, table_1.age, table_3.phone_num
FROM table_1
INNER JOIN table_3 ON table_1.id = table_3.id
WHERE table_1.id NOT IN (SELECT id FROM table_2);
  • Related