I have two tables NAVEEN_T1 and NAVEEN_T2 having columns like Id and Name.
How to swap name column values of both the tables on the basis of Id?
SQL> SELECT * FROM NAVEEN_T1; ID NAME ---------- ---------- 1 GOLDI 2 NAVEEN 3 AMIT SQL> SELECT * FROM NAVEEN_T2; ID NAME ---------- ---------- 1 RANJAN 2 SOM 3 ABHAY
I want output like:
SQL> SELECT * FROM NAVEEN_T1; ID NAME ---------- ---------- 1 RANJAN 2 SOM 3 ABHAY SELECT * FROM NAVEEN_T2; ID NAME ---------- ---------- 1 GOLDI 2 NAVEEN 3 AMIT
Thanks in advance.
Now, this might be oversimplified, but hey - that's what your sample data suggest. The idea is: exchange table names, not data. Have a look:
Here goes the trick:
Hope this will solve your problem ,i have created backup tables to capture the values. You can use temporary tables instead of permanent tables
Check here-http://sqlfiddle.com/#!9/fdc52e/2
You can try this
Something like that should do it easily.
The only tricky point I see is matching the row from table2 to the row from table1. In my example, I supposed both tables share an unique "id" column which enables easy matching. Modify the query with something more appropriate.