Link to home
Start Free TrialLog in
Avatar of FLOG51
FLOG51

asked on

MySQL Update Query using SELECT Statement

Hi

I am attempting to update a number of rows in a MySQL table with values from other rows within the same table and my attempts have failed. My attempt is below however it delivers the error message listed below the query.

UPDATE `Table` set `field_value` =
(SELECT `field_value` FROM `Table` WHERE `field_name` = 'xyz')
WHERE `field_name` = 'abc'

#1093 - You can't specify target table 'Table' for update in FROM clause

Basically I am attempting to use the Select Query to create the variable to use in the update Query.

Is this at all possible?

FLOG51
ASKER CERTIFIED SOLUTION
Avatar of rajvja
rajvja
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FLOG51
FLOG51

ASKER

Hi rajvja

Am I correct in assuming that you have used two tables in this query i.e. "src" and "tab"

I am only using one table which has the data I wish to use to update values in the same Table.

Thanks
FLOG51
Avatar of FLOG51

ASKER

Thanks for the attempted help guys, as 'a_b' has stated this is possible from multiple tables but not from one.