SELECT *
from

(
select
   w13.nr01 as nr01,
   w13.p02 as p02,
   w13.p03 as p03,
   0 as p101,
   0 as p102,
   0 as p103
FROM w13
WHERE w13.p01='{user_pswd}'

union

select
   0 as nr01,
   d80.p02 as p02,
   d80.p03 as p03,
   d80.nr01 as p101,
   if(w22.p04 is null, 0, w22.p04) as p102,
   if(w22.nr01 is null, 0, w22.nr01) as p103
FROM d80
LEFT JOIN w22 ON w22.p01='{user_pswd}'
              && w22.p02='D80_1'
              && w22.p03=d80.nr01
WHERE d80.p01='{peg_nr1}'

) AS T1
WHERE p102=0
ORDER BY p03;
