'Update The Data in the Exisiting table based on different levels in Spark sql

I have this Existing table tb1 in my database

enter image description here

Now new data comes and new data is stored in another table tb2

enter image description here

Earlier Account_Number 9988 was Level 2, But now in the new table it is Level 1

So the updated table tb1 should be :

enter image description here

How to achieve this result?



Solution 1:[1]

Below example can be used to resolve your issue.

INSERT INTO table_name TABLE table_name;

Above query should work

-- Assuming the visiting_students table has already been created and populated.
> SELECT * FROM visiting_students;
          name               address student_id
 ------------- --------------------- ----------
 Fleur Laurent 345 Copper St, London     777777
 Gordon Martin  779 Lake Ave, Oxford     888888

> INSERT INTO students TABLE visiting_students;

> SELECT * FROM students;
          name                   address student_id
 ------------- ------------------------- ----------
     Amy Smith     123 Park Ave,San Jose     111111
     Bob Brown  456 Taylor St, Cupertino     222222
 Cathy Johnson   789 Race Ave, Palo Alto     333333
 Dora Williams 134 Forest Ave, Melo Park     444444
 Fleur Laurent     345 Copper St, London     777777
 Gordon Martin      779 Lake Ave, Oxford     888888

Refer - https://docs.databricks.com/sql/language-manual/sql-ref-syntax-dml-insert-into.html#insert-using-a-table-clause

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AbhishekKhandave-MT