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