Issue
Table 1 -
col1 | col2 |
---|---|
1 | 443 |
2 | 449 |
3 | 479 |
Table 2 -
col1 | col2 |
---|---|
1 | NULL |
2 | NULL |
3 | NULL |
Note - col1 is not a PK
expected Output -
Table 2 -
col1 | col2 |
---|---|
1 | 443 |
2 | 449 |
3 | 479 |
This is my python code:
abc_df = pd.read_sql_query("UPDATE Table1 SET Table1_id = t2.col1 FROM Table1 t1
INNER JOIN Table2 t2 ON t1.col2 = t2.col2", con=connection)
But My Actual OUTPUT is -
Table 2 -
col1 | col2 |
---|---|
1 | 443 |
2 | 443 |
3 | 443 |
Solution
You need to update your UPDATE query -
UPDATE Table2 T2
SET col2 = T1.col2
FROM Table1 t1
WHERE T1.col1 = T2.col1
Answered By - Ankit Bajpai Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.