Можете да използвате агрегиране: select up, max(code_dept) as code_dept from ESP_ENSEIGNANT ee group by up;