"Steinar H. Gunderson" <sgunderson(at)bigfoot(dot)com> writes:
> BEGIN
> INSERT INTO kortsys2.mdb_gruppekobling_temp
> SELECT overgruppe_id,undergruppe_id FROM gruppekobling gk
> JOIN gruppe g1 ON gk.overgruppe_id=g1.gruppe_id
> JOIN gruppe g2 ON gk.overgruppe_id=g2.gruppe_id
> WHERE g1.aktiv AND g2.aktiv;
> LOOP
BTW, it sure looks like that second JOIN ought to be
JOIN gruppe g2 ON gk.undergruppe_id=g2.gruppe_id
As-is, it's not doing anything for you ... certainly not enforcing
that the undergruppe_id be aktiv.
regards, tom lane