Is this correct? You are sorting on group_id, id, level, number, node_id - but then deduping based upon fixing gruop_id and id and then a fuzzy condition upon node_id - ignoring level and number. This may be what you want but it is quite unusual