Použijte MAX -operátor a skupina podle UID . SELECT MAX(t.ID), t.UID FROM yourtable AS t GROUP BY t.UID;