So I have 2 tables which iam joining using Inner Join. Table 1 :
Name | Batch_Date | AcctID |
---|---|---|
Bob | 18-08-11 | 32 |
Bob | 19-08-11 | 32 |
Shawn | 18-08-11 | 42 |
Shawn | 20-08-11 | 42 |
Paul | 18-08-11 | 36 |
Paul | 19-08-11 | 36 |
Table 2
Code | order_Date | AcctID |
---|---|---|
1 | 18-08-11 | 32 |
0 | NULL | 32 |
0 | NULL | 42 |
0 | NULL | 42 |
1 | 18-08-11 | 36 |
1 | 18-08-11 | 36 |
So I want to get the name, last batch_date , AcctID from the table 1 and code, order date from table 2.
The challenge for me here is as there are multiple rows of same AcctId in table 2, if for any acctid, the date column is not null, I want to select that date and if date column is null for each row, I want to select the null value for date.
SO resulting dataset should look like below:
Name | Batch_Date | AcctID | Code | Order_Date |
---|---|---|---|---|
Bob | 19-08-11 | 32 | 1 | 18-08-11 |
Shawn | 20-08-11 | 42 | 0 | NULL |
Paul | 19-08-11 | 36 | 1 | 18-08-11 |