INSERT INTO us3
(nr01, p01, p02, p03, p04)

SELECT
  1 as nr01,
  t1.p01 as p01,
  t1.p02 as p02,
  t1.p03 as p03,
  t1.p04 as p04

FROM
(
select
   us3.nr01 as nr01,
   us0.p01 as p01,
   us4.p02 as p02,
   us4.p01 as p03,
   us0.p410 as p04
FROM us4
LEFT JOIN d24 ON d24.p02=us4.p01
LEFT JOIN us0 ON us0.p410=d24.p01
LEFT JOIN us3 ON us3.p01=us0.p01 && us3.p02=us4.p02
WHERE us0.p410='{peg_nr1}'
ORDER BY us0.p01, us4.p02
) as t1
WHERE t1.nr01 IS NULL
GROUP BY t1.nr01, t1.p01, t1.p02, t1.p04 ;

