In standard SQL, you can simply attach the table to yourself:
select a.name, b.name from t as a, t as b where a.surname = b.surname and a.id < b.id
where t is your table and id is the primary key column.
This returns all even pairs of first names for each last name with multiple entries.
You might want to add surname to the list of selected columns.
source share