Update query resulting wrongly

后端 未结 1 1851
清歌不尽
清歌不尽 2021-01-29 09:33

I have table called company_emp. In that table I have 6 columns related to employees:

  1. empid
  2. ename
  3. dob
  4. doj, ...
相关标签:
1条回答
  • 2021-01-29 10:25

    You're updating every row in the company_name/emp table.

    You can fix that with a correlated subquery to make sure the row exists, or more efficiently by placing a primary or unique key on bday.empid and querying:

    update (
      select c.dob to_dob,
             d.dob from_dob
      from   company_emp c join dob d on (c.empid = d.empid)
      where  d.dob = date '2011-05-01')
    set to_dob = from_dob
    

    Syntax not tested.

    0 讨论(0)
提交回复
热议问题