select *
FROM

(
select
   w11.nr01 as t_nr01,
   w11.nr01 as t_newnr,
   0 as t_del,
   w11.p01 as t_p01,
   w11.p02 as t_p02,
   w11.p03 as t_p03,
   0 as t_p101,
   0 as t_p102,
   0 as t_p103
FROM w11
WHERE w11.p01='{np01}'

UNION


select
   0 as t_nr01,
   0 as t_newnr,
   0 as t_del,
   space(10) as t_p01,
   d80.p02 as t_p02,
   d80.p03 as t_p03,
   d80.nr01 as t_p101,
   if(w22.p04 is null, 0, w22.p04) as t_p102,
   if(w22.nr01 is null, 0, w22.nr01) as t_p103
FROM d80
LEFT JOIN w22 ON w22.p01='{np01}'
              && w22.p02='D80'
              && w22.p03=d80.nr01
WHERE {p_us5where}

) as t1
ORDER BY t_p03;
