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

Python __call__ special method practical example -

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -