By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

update a table row using other tables

P: 1
Hi,
I have a table A , table B and table C.
Table B is kind of a bridge to table A and table C (i.e it has common columns that bridges table A and table C)
I have a colun in table A whose value is mismatching with that of table C. I need to update table A using table C but I don't have common columns except the column itself which I need to update. i need to do a join in order to update. I don's know how to write this query. If anyone can help me out, it would be a great help
Thanks
Vee
Jul 20 '07 #1
Share this Question
Share on Google+
2 Replies


mwasif
Expert 100+
P: 801
show table structure and some sample data.
Jul 21 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, veenaaecom. Welcome to TSDN!

You can update rows in one table using rows in other tables like this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE
  2.         `a`,
  3.         `b`,
  4.         `c`
  5.     SET
  6.         `a`.`field1` = 'someValue',    -- Set to a static value
  7.         `a`.`field2` = `c`.`Field2`    -- Data depends on another table
  8.     WHERE
  9.             `a`.`id` = `b`.`id`
  10.         AND
  11.             `b`.`id` = `c`.`id`
  12.         AND
  13.             `c`.`id` = '5';
  14.  
This query will update records in table `a` that correspond to the row in table `c` whose `id` is '5'. Note that if there is a many-to-many relationship between `a` and `c`, multiple rows might be updated, but only in table `a`.
Jul 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.