Jump to content

MySQL update statement


shaggycap

Recommended Posts

I am struggling with a SQL statement and hoped someone would be able to help :)

I have 2 tables:

customer_depots
contacts

Each table contain fields called 'customer_depot_id' and 'address_id'.

What I want to do is update the address_id in the contacts table, with the value of the address_id in the customer_depots table, only where the customer_id values match in each table, AND the address_id in the contacts table is equal to zero.

Does this make sense?

So, update address_id in contacts,
where address_id in contacts = address_id in customer_depots
and address id in contacts = zero.

This is because a number of address_id's are missing from the contacts table, and I want to replace them with the correspondingvalue from the other table.

I have got as far as a SELECT statement, which goes someway to explain things, but I need an UPDATE statement like I have explained above.

[code]SELECT cd.ADDRESS_ID FROM customer_depots cd, contacts con WHERE con.CUSTOMER_DEPOT_ID = cd.CUSTOMER_DEPOT_ID AND con.ADDRESS_ID = 0
[/code]
Hope someone can help :-*

thanks.






Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.