atheistrical
01-06-2010, 04:20 PM
I have two different tables with data in them namely
Table I (main_table)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
id | batch_no | name | type | ......................etc columns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 | 001 | ABC | 2 | ................
2 | 001 | BCA | 0 | ................
3 | 002 | ACB | 1 | ................
4 | 002 | CAB | 2 | ................
-------------and so on------------------------
Table II (other_table)
~~~~~~~~~~~
batch_no | type
~~~~~~~~~~~
003 | 3
001 | 1
002 | 0
006 | 2
----so-on------
The batch_no in Table I is not unique, while batch_no in Table II is unique column
Now, I wanted to update the columns of Table I with the corresponding data from Table II
I tried :
UPDATE Table_I AS t1
SET type=(SELECT type FROM Table_II AS t2)
WHERE t1.batch_no=t2.batch_no
Doesn't work!! Any suggestions?
Table I (main_table)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
id | batch_no | name | type | ......................etc columns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 | 001 | ABC | 2 | ................
2 | 001 | BCA | 0 | ................
3 | 002 | ACB | 1 | ................
4 | 002 | CAB | 2 | ................
-------------and so on------------------------
Table II (other_table)
~~~~~~~~~~~
batch_no | type
~~~~~~~~~~~
003 | 3
001 | 1
002 | 0
006 | 2
----so-on------
The batch_no in Table I is not unique, while batch_no in Table II is unique column
Now, I wanted to update the columns of Table I with the corresponding data from Table II
I tried :
UPDATE Table_I AS t1
SET type=(SELECT type FROM Table_II AS t2)
WHERE t1.batch_no=t2.batch_no
Doesn't work!! Any suggestions?