0

I've in mysql db two tables:

1) dotable_new;

2) dotable_new_new

Now I need update the value TOTAL in my table dotable_new of value TOTAL in my table dotable_new_new.

I'm trying this update query without success ... can you help me?

UPDATE dotable_new a, dotable_new_new tmp
SET a.total = tmp.total
WHERE
    a.rdt IN ('tot mac')

dotable_new;

+---------+---------------+--------+-------+----+
| RDT     | TYPE          | NUMBER | TOTAL | ID |
+---------+---------------+--------+-------+----+
| tot mac | tot           |   3209 |  3249 |  1 |
+---------+---------------+--------+-------+----+

dotable_new_new

+---------+-------+----+
| RDT     | TOTAL | ID |
+---------+-------+----+
| tot mac | 10899 |  5 |
+---------+-------+----+
Hamamelis
  • 1,983
  • 8
  • 27
  • 41

2 Answers2

1

check this will help you on how to join two tables in update

try that:

  UPDATE dotable_new a
  INNER JOIN dotable_new_new tmp ON tmp.rdt = a.rdt
  SET a.total =  tmp.total
  WHERE a.rdt = 'tot mac'
Community
  • 1
  • 1
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

Try this:

UPDATE dotable_new a
SET a.total = (SELECT tmp.total
               FROM  dotable_new_new tmp
               WHERE tmp.rdt = a.rdt)

If you want to update the record rdt = 'tot mac' only, then add the following line to the end:

WHERE a.rdt = 'tot mac'
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55