I have two tables that contain the people who work in the company and their employment data (so people are one table, employment is another). The table "People" contains information about where the person lives, emergency contact, phone number bla bla bla. The employment table contains information about where he works, the nearest boss and much more. These tables have been corrupted and now contain several duplicate claims. Both tables now have a Person identifier, but the busy identifier is only in busy. I need both numbers for all the people who have been duplicated.
This works great:
SELECT DISTINCT pp.Personid, pp.Firstname, pp.Lastname, pp.Address, FROM People pp JOIN People pp2 ON pp.Firstname = pp2.Firstname AND pp.Lastname = pp2.Lastname AND pp.Address = pp2.Address AND pp.Personid <> pp2.Personid ORDER BY pp.Firstname, pp.Lastname, pp.Personid
returns the following values ββ(but does not include the Employment number, as you can see):
1001 Carl Johnsson Bigstreet 1 1002 Carl Johnsson Bigstreet 1 1003 Carl Johnsson Bigstreet 1 1010 Andrew Wilkinsson Smallstreet 2 1011 Andrew Wilkinsson Smallstreet 2
Now, to add an id of employment, I join this table as follows:
SELECT DISTINCT pp.Personid, e.Employmentid, pp.Firstname, pp.Lastname, pp.Address, FROM People pp JOIN People pp2 ON pp.Firstname = pp2.Firstname AND pp.Lastname = pp2.Lastname AND pp.Address = pp2.Address AND pp.Personid <> pp2.Personid JOIN Employment e on pp.Personid = e.Personid ORDER BY pp.Firstname, pp.Lastname, pp.Personid
And everything goes to h ** l in the basket with the following result:
1001 1111 Carl Johnsson Bigstreet 1 1001 1111 Carl Johnsson Bigstreet 1 1001 1111 Carl Johnsson Bigstreet 1 1010 1234 Andrew Wilkinsson Smallstreet 2 1010 1234 Andrew Wilkinsson Smallstreet 2
As you can see, I get both Personid and Employmentid, but now I only get one (repeated the correct number of times), so I don't have all the other Personid and Employmentid on my list.
Why?
What happened to my formation that broke the party?