Sign Up

Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have permission to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Oraask Logo Oraask Logo
Sign InSign Up

Oraask

  • Write
    • Add A New Post
    • Ask A Question

Oraask Navigation

Search
Ask A Question

Mobile menu

Close
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
Home/ Questions/Q 3793
Next
In Process

Oraask Latest Questions

Question
PraveenM
  • 0
  • 0
PraveenMExplorer
Asked: June 18, 20162016-06-18T10:49:48+03:00 2016-06-18T10:49:48+03:00In: Oracle SQL

How can i Update a table by data in another table ?

  • 0
  • 0

i want to update my table with data in another table in oracle sql for example
Table 1:

ID    NAME         DESC
---------------------------
1     mac          first
2     donald       second
3     robert       third

 

Table 2:

ID    NAME        DESC
-----------------------
3     SALAH       forth
5     AHMED       fifth

 

so now i want to run sql update statement to update table 1 by data located in table 2 which is two table are equals in ID’s, so the final result would be like this

ID    NAME         DESC
---------------------------
1     mac          first
2     donald       second
3     SALAH        forth

thanks in advance.

databaseoraclesqlstatementupdate
1
  • 1 1 Answer
  • 1k Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    Related Questions

    • How to get Column Names from a Table in Oracle
    • What are the different types of case manipulation functions available in Oracle SQL
    • What is the use of ADD, DROP and MODIFY Commands
    • What are the differences between SQL and PL/SQL in Oracle
    • What is the use of LIMIT and OFFSET in SQL

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Hassan AbdElrahman
      Hassan AbdElrahman Master Oracle ACE Pro ♠ | Oracle Senior ERP Technical Consultant
      2016-06-18T11:06:40+03:00Added an answer on June 18, 2016 at 11:06 am

      This called correlated update you can find examples below

      UPDATE TABLE(<SELECT STATEMENT>) <alias1>
      SET <column_1> = (
        SELECT <column_1>
        FROM <table_2> <alias2>
        WHERE <alias2.table_name> = <alias1.table_name>);

      in you sample :

      UPDATE table1 t1
         SET (name, desc) = (SELECT t2.name, t2.desc
                               FROM table2 t2
                              WHERE t1.id = t2.id)
       WHERE EXISTS (
          SELECT 1
            FROM table2 t2
           WHERE t1.id = t2.id )

      alternative way you can do this

      UPDATE (SELECT t1.id, 
                     t1.name name1,
                     t1.desc desc1,
                     t2.name name2,
                     t2.desc desc2
                FROM table1 t1,
                     table2 t2
               WHERE t1.id = t2.id)
         SET name1 = name2,
             desc1 = desc2
      
      

      and now the final example is

      UPDATE Table1 T1 SET
      T1.name = (SELECT T2.name FROM Table2 T2 WHERE T2.id = T1.id),
      T1.desc = (SELECT T2.desc FROM Table2 T2 WHERE T2.id = T1.id)
      WHERE T1.id IN (SELECT T2.id FROM Table2 T2 WHERE T2.id = T1.id);
        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Adv 250x250

    Explore

    • Categories
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Dev Tools
      • Online Compiler
      • Base64 Converter
    • Wiki
      • SQL Tutorials
      • Java Tutorials
      • Python Tutorials
      • JavaScript Tutorials

    Footer

    Oraask

    About

    Oraask is a website for developers and software engineers who want to learn new skills, share their knowledge, and solve their coding problems. Oraask provides free content on various programming languages and topics, such as Oracle, Python, Java, etc. Oraask also allows users to ask questions and get answers from other members of the community.

    About Us

    • About Us
    • Contact Us

    Legal Stuff

    • Privacy Policy
    • Terms & Conditions

    Follow

    Oraask is licensed under CC BY-NC-SA 4.0Oraask CopyrightOraask CopyrightOraask CopyrightOraask Copyright

    © 2019 Oraask. All Rights Reserved
    With Love by Oraask.

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.