Sign Up

Sign Up to our social questions and Answers Engine 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 Engine 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

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:36:30+00:00 2026-05-29T07:36:30+00:00

I have two tables Emp & Dept. SQL> select * from emp where rownum<4;

  • 0

I have two tables Emp & Dept.

SQL> select * from emp where rownum<4;

     EMPNO ENAME      JOB              MGR        SAL     DEPTNO
---------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902        800
      7499 ALLEN      SALESMAN        7698       1600
      7521 WARD       SALESMAN        7698       1250

SQL> select * from dept;

    DEPTNO DNAME           LOC                  EMPNO
---------- --------------- --------------- ----------
        10 ACCOUNTING      NEW YORK              7369
        20 RESEARCH        DALLAS                7499
        30 SALES           CHICAGO               7521
        40 OPERATIONS      BOSTON

i want to update deptno of emp which should be same as deptno of dept table & where empno of dept should be equal to empno of emp; In short i want to update dept using inner join operation with emp;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:36:31+00:00Added an answer on May 29, 2026 at 7:36 am

    In Oracle, the canonical way to do it is the MERGE statement:

    MERGE INTO emp e
    USING dept d
       ON (d.empno = e.empno)
     WHEN MATCHED THEN UPDATE SET e.deptno = d.deptno
    

    However the above will not work if you are using Oracle 9 (see below), or if there are domain index on your tables (Oracle Text for instance)

    I asked a question previously about what MERGE statements do.

    It is necessary that each row of e be connected by the join condition (ON section) to none or exactly 1 row of d, otherwise you’ll get ORA-30926 “Unable to get a stable set of rows in the source tables”.

    Rows of e not connected to any department get unchanged, rows of d not connected to any employee could be used for INSERTS (and in Oracle 9 must be used in a WHEN NOT MATCHED THEN INSERT(cols) VALUES(...) clause; if you’re using Oracle 9 then this answer is not suitable for you).

    Another option, but subject to the same underlying restrictions:

    UPDATE (SELECT e.deptno edeptno, d.deptno ddeptno
              FROM emp e, dept d
             WHERE e.empno = d.empno)
       SET edeptno = ddeptno
    

    Or

    UPDATE emp
       SET deptno = ( SELECT deptno FROM dept WHERE empno = emp.empno )
     WHERE empno IN ( SELECT empno FROM dept )
    

    As you can see solutions are numerous but subject to constraints.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: emp (empno,ename) address(empno,address) emp can have 0 or more address.
Suppose I have a dataset with those two immortal tables: Employee & Order Emp
I have a query which is crossing two tables select count(*) from ingenium.empevt, ingenium.evt
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
Let's say I have two tables, employee and department where emp has a @ManyToOne
I have two tables: EMP emp_id | Name | Surname | 1 | Bob
Suppose I have two tables 1st table emp EmpID | EmpName|xyz...coloums 1. | Hrishi
I have two tables called lawyer & client.And they are the users of my
I have two tables in MySql Company : (cname,city) works : (ename,cname,salary) I want
I have two tables USER and TRANSACTION i want to choose the data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.