sql - how to find people with same family name? -


you have table 4 columns:

primary key / name / surname / middle name

how write sql query find people has same family name?

1 / ivan / ivanov / ivanovich

2 / petr / levinsky / aleksandrovich

3 / alex / ivanov / albertovich

should return ivan , alex

thanks

in standard sql can join table itself:

select a.name, b.name t a, t b a.surname = b.surname , a.id < b.id 

where t table , id primary key column.

this returns distinct pairs of first names every surname has multiple entries.

you might want add surname list of selected columns.


Comments

Popular posts from this blog

c# - Getting control value when switching a view as part of a multiview -

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -