Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to loop over records and then search into another table and if not found then insert it after fetching records from another table in oracle?

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading