Home  >  Q&A  >  body text

mysql - Update problem of related data table

UPDATE a,b SET a.v_publishyear = b.v_publishyear WHERE a.v_id = b.v_e

I want to update the data in table a. There should actually be more than 9,000 pieces of data, but in fact only 120 pieces of data can be updated. How is this going.
Update the publishyear field in table b to the corresponding publishyear field in table a.

But when I perform the operation

SELECT * FROM a table, b table where a table.c field = b table.d field
During this query, more than 9,000 pieces of data can be queried. What is going on?
Me What went wrong in the update data code?

天蓬老师天蓬老师2701 days ago631

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-27 17:41:06

    UPDATE is not suitable for using WHERE to associate two tables. So try writing it this way:

    UPDATE a LEFT JOIN b ON a.v_id = b.v_e SET a.v_publishyear = b.v_publishyear

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:41:06

    update tableA a
        set a.v_publishyeaar=(select b.v_publishyear from tableB b where b.v_e=a.v_id)

    reply
    0
  • Cancelreply