× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Performance and reliability would be better if you wrote the query to avoid the duplicates to begin with. I added a "distinct" to the selection below. You could also use "group by" instead.

Insert into Table_B (Field_A)
Select distinct(field_a)
From Table_A
Where Field_A not in (select * from table_b)



INSERT into TABLE_B (FIELD_A)
(SELECT distinct(FIELD_A)
from TABLE_A
where FIELD_A not in (Select Field_A from TABLE_B)

-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Niels Liisberg
Sent: Monday, April 17, 2023 11:39 AM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Is it possible to create a sub select where the sub select refreshes itself for each record read?

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.


Yes - but you have to use a MERGE INTO ....

On Mon, Apr 17, 2023 at 5:37 PM a4g atl <a4ginatl2@xxxxxxxxx> wrote:

This is one I always need.

I am reading table_A and need to check if the record exists in TABLE_B.
If it does not exist in tableB, I need to add it to table_B.

Problem is this will generate duplicate records.

Is there a way to have the sub select refresh itself before the next
SELECT is executed? I would like the sub select to be dynamic and
sensitive to each insert.

Example:
INSERT into TABLE_B (FIELD_A)
(SELECT FIELD_A
from TABLE_A
where FIELD_A not in (Select Field_A from TABLE_B)

TIA, Darryl Freinkel.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.