update query with join on two tables

Posted by dba_query on Stack Overflow See other posts from Stack Overflow or by dba_query
Published on 2010-05-12T03:27:22Z Indexed on 2010/05/12 3:34 UTC
Read the original article Hit count: 230

Filed under:
|

I have customer and address tables.

query:

select * from addresses a, customers b where a.id = b.id

returns 474 records

For these records, I'd like to add the id of customer table into cid of address table.

Example: If for the first record the id of customer is 9 and id of address is also 9 then i'd like to insert 9 into cid column of address table.

I tried:

update addresses a, customers b set a.cid = b.id where a.id = b.id

but this does not seem to work.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql