asmith Posted December 16, 2007 Share Posted December 16, 2007 update tablename set username=name where id="1" the above code put the value of name column in the username column where row is 1 . how can i put the value of the "name" column which is in row="2" , in the username column in row="1" ? Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/ Share on other sites More sharing options...
~n[EO]n~ Posted December 16, 2007 Share Posted December 16, 2007 That cannot be done I think Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/#findComment-416176 Share on other sites More sharing options...
Zane Posted December 16, 2007 Share Posted December 16, 2007 UPDATE tablename SET username = ( SELECT name FROM tablename WHERE id = 2 LIMIT 1) WHERE id = 1; maybe? Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/#findComment-416187 Share on other sites More sharing options...
~n[EO]n~ Posted December 16, 2007 Share Posted December 16, 2007 @zanus : that was near but didn't work MySQL said: #1093 - You can't specify target table 'table_name' for update in FROM clause Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/#findComment-416196 Share on other sites More sharing options...
asmith Posted December 16, 2007 Author Share Posted December 16, 2007 yea close one ! gave me that error too ! what a shame !! :-\ Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/#findComment-416204 Share on other sites More sharing options...
fenway Posted December 18, 2007 Share Posted December 18, 2007 You can't update the source table in the same statement... this is known limitation. Quote Link to comment https://forums.phpfreaks.com/topic/81903-get-value-from-another-row/#findComment-417336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.