UPDATE table2 SET column1_table2 = ( SELECT column1_table1
FROM table1 WHERE column2_table1 = column2_table2 LIMIT 1)
LIMIT 2
So what I'm trying to do is to find a corresponding value and then I'm adding it into table2. Now how can I actually delete this value after this has been added to table2 immediately?
Well I don't know how to write that... I'm not storing any information in any variable right? What I want is once it inserts it has to delete that particular one from the other table...
UPDATE table2 SET column1_table2 = ( SELECT column1_table1
FROM table1 WHERE column2_table1 = column2_table2 LIMIT 1 AND DELETE column1_table1
FROM table1 WHERE column2_table1 = column2_table2 LIMIT 1)
LIMIT 2
Actually one another doubt I had was.. When I have to do many such operations (typically on a million records)... I mean first lookup for a value in table2 and then add it to table1, will it help to actually delete those values from the table so that I need not have to iterate over them everytime?