Gunakan MAX -operator dan grup dengan UID . SELECT MAX(t.ID), t.UID FROM yourtable AS t GROUP BY t.UID;