SELECT tbl01.*,
       ifnull(p07.p06, '') as p07_p06
FROM 
(
     select nr01 as nr01, 
            p02 as p02, 
            p03 as p03, 
            p04 as p04 
     from p20  
     where p01='{p_asctbl}' 
        && (p06=1 || p06=3)  

     UNION ALL 

     select nr01 as nr01, 
            p04 as p02, 
            p01 as p03, 
            p02 as p04 
     from p20  
     where p03='{p_asctbl}' 
     && (p06=1 || p06=2)
)as tbl01
left join p07 ON p07.p01=tbl01.p03
group by nr01;