SELECT
   ifnull(t1.nnn, 0) as nr01,
   t1.p01  as p01,
   t1.p02  as p02,
   t1.p30  as p30

FROM

(
select
   us2.nr01 as nr01,
   us2.p01  as p01,
   us2.p02  as p02,
   us2.p30  as p30,
   us4.nr01 as nnn
from us2
LEFT JOIN us4 ON us4.p02=us2.p01
              && us4.p01='{np01}'
              && us4.p01<>''
ORDER BY us2.p01

) as t1
WHERE t1.p02<>'' && 
      (t1.nnn=0 || t1.nnn IS NULL);