Page 1 of 1

UPDATE...WHERE...

Posted: Thu Sep 26, 2002 12:27 pm
by gastonlm
I have two tables t1 and t2, and I have a text(description). At t1 I have the code and at t2 the description of the code and it's foreign key.
I need to update fields in t1. Is it possible with this code?

Code: Select all

UPDATE t1, t2 SET t1.field1 = value WHERE t1.ID = t2.FK AND t2.text = description
FK = FOREIGN KEY
Am I clear?

Posted: Thu Sep 26, 2002 2:40 pm
by twigletmac
I don't know if which db you're using but if it's MySQL read this:
http://www.mysql.com/doc/en/UPDATE.html

Mac

Posted: Fri Sep 27, 2002 8:25 am
by BDKR
I don't know which database you are using, but the query looks good to me.

Well, now that I look at it again, if you are only updating t1, then perhaps it should look like...

Code: Select all

UPDATE t1 SET t1.field1 = value WHERE t1.ID = t2.FK AND t2.text = description
One more thing. Many databases provide a way hacking queries directly into the database. Mysql, Sysbase, Postgres, and mSQL are all good examples of this.

Cheers,
BDKR