0

I need to update multiple rows in a table.

i have table customer and contact

I need to update customer where the linked contact in the contact table has the column city at a certain value. I can get the rows i need with this query

Select cus.id, con.city 
from customer cus, contact con 
where cus.contacts_id=con.id 
  and con.city="MyValue"

I know how to update one table but do not understand how to update the table when the rows are looked up from a different table.

1
  • and con.city="MyValue" will result in an error unless you have a column named MyValue somewhere. String constants need to be enclosed in single quotes in SQL.
    – user330315
    Commented Sep 7, 2016 at 11:31

1 Answer 1

2

Firstly, please do not use the old JOINs (FROM comma separated tables).

Secondly, here you go:

UPDATE customer SET whatever = 'whatever value'
WHERE contacts_id IN (
    SELECT id FROM contact WHERE city="MyValue"
)
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.