Subject table insert into itself - can this be done?
Author p51b.mustang
Hi,
I am seeking advice on whether this is possible:-

insert into table_X (mydatetime, taskcode, sitecode)
Select x.mydatetime, x.taskcode, ss.sitecode
From table_X x
inner join sites ss on (ss.siteparentcode=x.sitecode)
Where (x.mydatetime between '30 nov 2010' and '1 nov 2011');
/* table_X has no keys */
In other words a table inserting into itself. Essentially for a particular sitecode the records are duplicated for each sitecode relationship.

On the left side of my brain, I say firebird would collect all records from the select first and then perform inserts with no problems.
On the right side, I say as records are inserted these very same records my be gathered into the select and also be duplicated with horrifying results.

Any thoughts would be appreciated.

with thanks in advance
David