You have a table with 4 columns:
Primary key / name / surname / middle name
How to write Sql query to find people who has same family name?
1 / Ivan / Ivanov / Ivanovich
2 / Petr / Levinsky / Aleksandrovich
3 / Alex / Ivanov / albertovich
Should return Ivan and Alex
Thanks
Websites like Genesreunited, Ancestry, My Heritage are some examples of sites that accept GEDCOM pedigree files, but there are many more. Rootsweb lists can be useful resources to find people searching the same surnames, places or subjects as you.
One of the most common is through the parental shared name. As with a lot of traditions, most people share their last name with their father who got their father's name upon birth. This means the scenario where you share the last name with a cousin is via your father's brother's children.
Use genealogy websites. Websites like Ancestry.com and FindAGrave.com are a good starting point, and some offer free trials. These sites have access to US census records, birth, marriage, death certificates, and other family trees that may intersect your own.
Well, use Facebook. Facebook has a Family search option that lets you search Facebook members by their family name. Just type in a few character of your last name in the search box and it will show you a paginated list of all Facebook members that share the same last name.
In standard SQL you can simply join the table with itself:
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 distinct pairs of first names for every surname that has multiple entries.
You might want to add surname
to the list of selected columns.
If you want to find exactly names then you should firstly find all surnames that appear more than once and the find all names:
select name
from t
where surname in (select surname from t group by surname having count(surname) > 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With