SELECT *
FROM 
(    SELECT a58.*, 
            ifnull(a90.nr01, 0) as a90nr01, 
            ifnull(a90.p30, '') as a90p30
     FROM a58 
     LEFT JOIN a90 ON a90.tbl='a58'
                   && a90.tbl_nr01=a58.nr01
     WHERE a58.nr01='{peg_nnn}' 
     GROUP BY a58.nr01
) as tbl01
ORDER BY vd100, nr01;