Join both the tables and get first table data and second table data which is missing in Table1 by comparing on Col1 and Col11 I guess. As all the ID’s (Col1 and Col11) should come together
Table1
Col1 Col2 Col3 Col4 Col5 Col6
1345653 330760137950 2012-07-09 21:40:29 1345653 331760137950 1341895229
1345653 110909316904 2012-07-09 21:29:06 1345653 111909316904 1341894546
1345653 221065796761 2012-07-09 19:31:48 1345653 221065796761 1341887518
Table2
Col11 Col22 Col33
1345653 330760137950 2012-07-09 21:40:29
1345653 110909316904 2012-07-09 21:29:06
1345653 221065796761 2012-07-09 19:31:48
1345653 **150851771618** 2012-07-09 18:57:33
If you look above two tables data, last line in Table2 means Col22-150851771618 is missing in Table1. So I need to display Table1 full data and last line from Table2 as Col22 is missing in Table1 by joining on Col1 and Col11, like this below output.
1345653 330760137950 2012-07-09 21:40:29 1345653 331760137950 1341895229
1345653 110909316904 2012-07-09 21:29:06 1345653 111909316904 1341894546
1345653 221065796761 2012-07-09 19:31:48 1345653 221065796761 1341887518
1345653 **150851771618** 2012-07-09 18:57:33 NULL NULL NULL
How can I do this using JOIN by joining on Col1 and Col11? I am having lot of confusion on this. Can anyone help me?
Update:- Some more scenarios
Table1
Col1 Col2 Col3 Col4 Col5 Col6
1345653 330760137950 2012-07-09 21:40:29 1345653 331760137950 1341895229
1345653 110909316904 2012-07-09 21:29:06 1345653 111909316904 1341894546
1345653 221065796761 2012-07-09 19:31:48 1345653 221065796761 1341887518
704318001 320941581940 2012-07-09 14:44:48 704318001 321941581940 1341870288
Table2
Col11 Col22 Col33 Col44 Col55 Col66
1345653 330760137950 2012-07-09 21:40:29 NULL NULL NULL
1345653 110909316904 2012-07-09 21:29:06 NULL NULL NULL
1345653 221065796761 2012-07-09 19:31:48 NULL NULL NULL
1345653 **150851771618** 2012-07-09 18:57:33 NULL NULL NULL
704318001 **290738585064** 2012-07-09 14:36:49 NULL NULL NULL
So Output should be like this- Meaning for this 1345653 ID, I need all record at same place and same with 704318001. So if you look the output, all the 1345653 are together and all 704318001 are together.
1345653 330760137950 2012-07-09 21:40:29 1345653 331760137950 1341895229
1345653 110909316904 2012-07-09 21:29:06 1345653 111909316904 1341894546
1345653 221065796761 2012-07-09 19:31:48 1345653 221065796761 1341887518
1345653 **150851771618** 2012-07-09 18:57:33 NULL NULL NULL
704318001 320941581940 2012-07-09 14:44:48 704318001 321941581940 1341870288
704318001 **290738585064** 2012-07-09 14:36:49 NULL NULL NULL
Basically, get the first table full and second table whose data is not there in Table1
A
LEFT JOINshould work..But based on your data, I think you should be joining on
Col22toCol2, sinceCol1andCol11don’t have unique values, so I don’t know how they are associated.