Query logic

I run a process that loads a table(tableA) and during this process I run function that does a check and if it doesn't pass my check I put it in a table(tableB) to be looked at by another department.
Now they have asked me if ALL records for an single ID get inserted into tableB and there are no records for that ID in tableA then they want to see all records in the program, which means I have to Insert into tableA(copy). So Im thinking Id run the whole process and check the tables after they end up where they do and run something like this
.
SELECT  * FROM tableB WHERE ID NOT IN(SELECT ID FROM tableA);
If I get rows back then do the Insert. So Im wondering if there is a better way of accomplishing what I need or are there any other opinions on how they would do this? Should I use NOT EXISTS instead? Any tips would help me out
Thanks
jknj72Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
Left join and then select when the joined row is null

Select ... from tablea a
Left join tableb b on a.id = b.id
Where b.id IS NULL

That should be fastest or as fast as using NOT EXISTS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Commented:
You might try a merge -
merge into tablea a
using tableb b
on (a.id = b.id)
when not matched then
insert(tablea columns) values (tableb columns)
0
jknj72Author Commented:
Thanks
0
awking00Commented:
Interesting. I thought you were trying to insert into tableA.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.