l.res_table = 'res_x' and 
(l.user_id = @user) and (l.res_id = r.res_id) and l.sequence > 1 and l.seen=0 and 
(r.status <> 'END' and r.status <> 'DEL' and r.status <> 'ATT' and r.status <> 'VAL') 
and is_folder = 'Y'