Ask Your Question

How to update fields in base from another table? [closed]

asked 2016-08-25 22:46:12 +0200

Quarto Die gravatar image

I would like bring in data from one table to another. I have two tables, "Calendar1" and "Calendar2", these two tables are joined on the field "ID1" "ID2" (I do not know if the joined relationship is correct. I would like to copy information from the field "Event1" in Calendar1 to "Event2" in Calendar in those cases where "event2" has currently no data. I have tried this UPDATE "Calendar2" SET "Event2"= "Calendar1"."Event1" WHERE "Calendar2"."Event2"=NULL This doesnt work. Even if I simplify the command and say UPDATE "Calendar2" SET "Event2"= "Calendar1"."Event1" I get the message Column not found: Calendar1.Event1 . Any ideas. Maybe something is wrong with the relationship in which I have chosen "update cascade".

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-10 23:07:14.801544

1 Answer

Sort by » oldest newest most voted

answered 2016-08-26 00:23:40 +0200

Ratslinger gravatar image

updated 2016-08-26 00:24:15 +0200

There are a few things wrong with your statement. The statement doesn't know where the field "Calendar1"."Event1" is coming from. Next it doesn't know what records from "Calendar1" it should get "Event1" from. Finally = NULL should be IS NULL. Here is a correct statement using MYID field to match records:

UPDATE "Calender2" SET "Event2"= (SELECT  
       "Calender1"."Event1" FROM "Calender1"  WHERE "Calender1"."MYID" = "Calender2"."MYID")
   WHERE "Calender2"."Event2" IS NULL

Of course you need to change "MYID" to the field you are matching on.

edit flag offensive delete link more


Thank you very much!

Quarto Die gravatar imageQuarto Die ( 2016-08-26 01:07:23 +0200 )edit

Thanks a lot. Exactly the answer I was looking for. Other syntax from general MySql code do not work.

silvain gravatar imagesilvain ( 2017-03-27 20:59:20 +0200 )edit

Question Tools



Asked: 2016-08-25 22:46:12 +0200

Seen: 971 times

Last updated: Aug 26 '16