I need to write a SQL statement that can merge duplicate field(s) and create single records into a Cursor
For example:
Table1 (Main)
First,Last,Name,Address,City,State,ZipCode
1. Winston,Smith,Winston Smith,123 Anywhere St,Chicago,IL,60601
2. Andrea,Lopez,Andrea Lopez,235 N Ave,Lawrence,NJ,08648
3. Sandra,Johnson,Sandra Johnson,2500 8th St,Los Angeles,CA,90061
4. Kate,Wilson,Kate Wilson,987 M Blvd,Tarzana,CA,91356
Table2 (Duplicates)
First,Last,Name,Address,City,State,ZipCode
1. Robert,Smith,Robert Smith,123 Anywhere St,Chicago,IL,60601
2. Jami,Smith,Jami Smith,123 Anywhere St,Chicago,IL,60601
3. Brit,Smith,Brit Smith,123 Anywhere St,Chicago,IL,60601
4. Justin,Abe,Justin Abe,123 Anywhere St,Chicago,IL,60601
5. John,Lopez,John Lopez,235 N Ave,Lawrence,NJ,08648
6. Jane,Hernandez,Jane Hernandez,235 N Ave,Lawrence,NJ,08648
7. Kim,Eyre,Kim Eyre,987 M Blvd,Tarzana,CA,91356
In this case records Table1 (rec 1) matches table2 (rec 1, 2, 3 and 4) because of the same address, city st & zip.
Table1 (rec 2) matches table2 (rec 5 & 6)
Table1 (rec 3) does not have a match
Table1 (rec 4) matches table2 (rec 7)
The cursor would result in
Name1 Name2 Name3 Name4 Name5 Address City State ZipCode
1. Winston Smith Robert Smith Jami Smith Brit Smith Justin Abe 123 Anywhere St Chicago IL 60601
2. Andrea Lopez John Lopez Jane Hernandez 235 N Ave Lawrence NJ 08648
3. Sandra Johnson 2500 8th St Los Angeles CA 90061
4. Kate Wilson Kim Eyre 987 M Blvd Tarzana CA 91356
and so on...
Up to 6 or 7 names for the same address.
I did make a key field (match1) (See image) on both tables, so I can find the matching records from table2, but I cannot seem able to write the correct SQL statement to create the cursor from both tables.
I have been at it for a few days and have not been able to create it. Pointing me in the correct direction is appreciated.
It might be a very simple answer but one I admit I have not been able to find.
Thanks.
Using VFP 9
For example:
Table1 (Main)
First,Last,Name,Address,City,State,ZipCode
1. Winston,Smith,Winston Smith,123 Anywhere St,Chicago,IL,60601
2. Andrea,Lopez,Andrea Lopez,235 N Ave,Lawrence,NJ,08648
3. Sandra,Johnson,Sandra Johnson,2500 8th St,Los Angeles,CA,90061
4. Kate,Wilson,Kate Wilson,987 M Blvd,Tarzana,CA,91356
Table2 (Duplicates)
First,Last,Name,Address,City,State,ZipCode
1. Robert,Smith,Robert Smith,123 Anywhere St,Chicago,IL,60601
2. Jami,Smith,Jami Smith,123 Anywhere St,Chicago,IL,60601
3. Brit,Smith,Brit Smith,123 Anywhere St,Chicago,IL,60601
4. Justin,Abe,Justin Abe,123 Anywhere St,Chicago,IL,60601
5. John,Lopez,John Lopez,235 N Ave,Lawrence,NJ,08648
6. Jane,Hernandez,Jane Hernandez,235 N Ave,Lawrence,NJ,08648
7. Kim,Eyre,Kim Eyre,987 M Blvd,Tarzana,CA,91356
In this case records Table1 (rec 1) matches table2 (rec 1, 2, 3 and 4) because of the same address, city st & zip.
Table1 (rec 2) matches table2 (rec 5 & 6)
Table1 (rec 3) does not have a match
Table1 (rec 4) matches table2 (rec 7)
The cursor would result in
Name1 Name2 Name3 Name4 Name5 Address City State ZipCode
1. Winston Smith Robert Smith Jami Smith Brit Smith Justin Abe 123 Anywhere St Chicago IL 60601
2. Andrea Lopez John Lopez Jane Hernandez 235 N Ave Lawrence NJ 08648
3. Sandra Johnson 2500 8th St Los Angeles CA 90061
4. Kate Wilson Kim Eyre 987 M Blvd Tarzana CA 91356
and so on...
Up to 6 or 7 names for the same address.
I did make a key field (match1) (See image) on both tables, so I can find the matching records from table2, but I cannot seem able to write the correct SQL statement to create the cursor from both tables.
I have been at it for a few days and have not been able to create it. Pointing me in the correct direction is appreciated.
It might be a very simple answer but one I admit I have not been able to find.
Thanks.
Using VFP 9