I have a table with survey data and another with data about each respondent to the survey. One table (data) has 3 fields “name”, “contact” and “participate”.
The other table (attributes) contains more details about the “name” and also contains a “participate” value.
I would like to update table data with the “participate” value from table “attributes”, if the “name” in table “attributes” matches either the “name” or “contact” in table “data”.
I wrote this:
UPDATE data
SET participate = (SELECT attributes.participate
FROM attributes
WHERE attributes.name = data.name)
This updates the “participate” value in the “data” table, but how can I also update the “participate” value if the name also appears in the contact field of the “data” table?
If I run another query with:
WHERE attributes.name = data.contact
then this updates all values in the “data” table, rather than only the ones that match.
Your help would be appreciated!
Give this a try: