PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] How to update all the value from one column to another

 October 23, 2022     join, postgresql, sql, sql-update     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing