cursor update + insert

hello guys,

I have a question, I have two tables with exactly the same settings example:


table1
NAME, AGE, DATE, IDENTIFIER, PHONE

table2
NAME, AGE, DATE, IDENTIFIER, PHONE

Table 1 is updated every day and I need to mount a cursor to read the record and compare to table2 record if they match make an update in table2 with data from table1.

if you have data in table1 in table2 that do not have an insert in table2 as I assemble this structure?
eduardo12foxAsked:
Who is Participating?
 
DoutorApedeutaCommented:
Hi,

Do you really need that cursor. I think you could easily solve the problem using this sintax:

insert into t1(a, b, c)
    select d, e, f from t2
    on duplicate key update b = e, c = f;

This, of course, assuming that there are unique keys in the tables.

Check this article for more info.
0
 
EmesCommented:
Try to use this

insert into table2
select NAME, AGE, DATE, IDENTIFIER, PHONE
FROM   table1
WHERE  NOT EXISTS
  (SELECT NAME, AGE, DATE, IDENTIFIER, PHONE
   FROM   table2
   WHERE  table2.NAME = table1.Name
and table2.Age = table1.age

and table2.date = table1.date
and table2.IDENTIFIER = table1.IDENTIFIER
and table2.PHONE = table1.Phone)
0
 
eduardo12foxAuthor Commented:
Fantastico! The insert was perfect but I can not implement UPDATE
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
eduardo12foxAuthor Commented:
Ok ok but to insert and find lines like how when I update the same line without the insert?
0
 
eduardo12foxAuthor Commented:
OK! Fantastico was correct and helped me a lot. I want to thank everyone's attention. Thank you!!
0
 
eduardo12foxAuthor Commented:
OK! Fantastico was correct and helped me a lot. I want to thank everyone's attention. Thank you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.