Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
Avatar of jknj72
jknj72

ASKER

Thanks
Interesting. I thought you were trying to insert into tableA.