skip to Main Content

This is my Table
enter image description here

I want to copy the "date_email2" data for "18458" id to some specific order id like 18460 and 18468. Can anyone please help me what is the easiest way to do it enter image description here

I want to copy the red data on blue box

2

Answers


  1. I assume your table is called orders so you can update this like this

    UPDATE orders
    SET date_email2 = (SELECT date_email2 FROM (SELECT * FROM orders) o WHERE id_order = 18458 ORDER By date_email2  DESC LIMIT 1) 
    WHERE id_order  IN (18460 , 18468)
    
    Login or Signup to reply.
  2. You can use join in MySQL:

    update mytable t cross join
           (select t2.*
            from mytable t2
            where t2.id_order = 18458
           ) t2
        set t.date_email2 = t2.date_email2
        where t.id_order in (18460, 18468);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search