Hi,
I've got two tables, each containing similar and different data. I want to determine the data in the one that is not in the other and vica versa.
There seems to be differences in some of the Id numbers.
Table1:
firstname surname ID
beauty sithole 6104100333081
monna monareng 1401120000000
Table2:
Field5 Field10 Field11
6104100333081 B SITHOLE
1401120147086 M MONARENG
Field10 being the initials of the person - first letter of firstname
There are approximately 2500 records in each table, the above query returns only 200
and I know for sure that it should be around 2000 that are similar.
This query returns approx 600 but a large amount of them are still incorrect
At the moment I'm stuck - Any help to fine tune this perfect
example of how differing data can make your life hell...
I've got two tables, each containing similar and different data. I want to determine the data in the one that is not in the other and vica versa.
There seems to be differences in some of the Id numbers.
Table1:
firstname surname ID
beauty sithole 6104100333081
monna monareng 1401120000000
Table2:
Field5 Field10 Field11
6104100333081 B SITHOLE
1401120147086 M MONARENG
Field10 being the initials of the person - first letter of firstname
Code:
SELECT *
FROM `Table1`
LEFT JOIN `Table2` ON LEFT( `Table1`.id, 6 ) = LEFT( Table2.Field5, 6 )
WHERE LOWER( `Table1`.Surname ) = LOWER( `Table2`.Field11 )
AND LOWER( LEFT( `Table1`.`FirstName` , 1 ) ) = LOWER( LEFT( `Table2`.Field10, 1 ) )
There are approximately 2500 records in each table, the above query returns only 200
and I know for sure that it should be around 2000 that are similar.
Code:
SELECT `Table1`. *
FROM `Table1`
LEFT JOIN Table2 ON `Table1`.id = Table2.Field5
WHERE Table2.Field5 IS NULL
ORDER BY `Table1`.id
This query returns approx 600 but a large amount of them are still incorrect
At the moment I'm stuck - Any help to fine tune this perfect
example of how differing data can make your life hell...