I have been trying to update the data behind a SELECT query, but not getting too far, so I have created a new database, with the hope of finding a solution.
I have two tables:
table_a
and table_b
table_a:
ID, item_to_match, new_value *(this is initially blank)*
table_b:
IDB, item_to_match, new_value *(the value I want to get into table_a)*
Somehow, I want to update new_value
in table_a with new_value
from table_b - but I can't seem to get it (I am new to this).
I tried creating an UPDATE query, but that only allowed me to show one of the two tables. So I tried creating a master query (called main
), thinking I could create an UPDATE query on that - but I can't get that to work either. Here is the syntax:
SELECT
`table_a`.`new_value` AS `goingto`,
`table_b`.`new_value` AS `takenfrom`
FROM (`table_a`
JOIN `table_b`
ON ((`table_a`.`item_to_match` = `table_b`.`item_to_match`)))
I really, really would appreciate a bit more guidance on how to do this (sorry to keep asking).
I have now tried three variations and keep getting the same error message. But here are the variations:
UPDATE table_a, table_b
SET table_a.new_value = table_b.new_value
WHERE table_a.item_to_match = table_b.item_to_match
UPDATE table_a a
INNER JOIN table_b b ON a.item_to_match = b.item_to_match
SET a.new_value = b.new_value
UPDATE table_a a,table_b b
SET a.new_value = b.new_value
WHERE a.item_to_match = b.item_to_match
The field item_to_match
is not a primary key or indexed (FYI)...
What the heck am I doing wrong???
I also just tried:
UPDATE table_a a
JOIN table_b b
ON a.item_to_match = b.item_to_match
SET a.new_value = b.new_value
Is the syntax right....am I doing something wrong in the app itself?