Zojak_Quaguz Posted December 21, 2010 Share Posted December 21, 2010 Table "people" has two columns: ID_NUMBER varchar(5), NAME varchar(20). Sample rows: 1 John 2 Steve 3 Suzy 4 Janet Table "relationships" has two columns: PERSON1 varchar(20), PERSON2 varchar(20). Sample rows: 1 2 1 3 1 4 2 3 2 4 3 4 I want to replace the numbers in table "relationships" with the matching names from table "people". I tried UPDATE people p, relationships r SET r.PERSON1 = p.NAME WHERE r.PERSON1 = p.ID_NUMBER; which worked fine, then I tried to update the second column with UPDATE people p, relationships r SET r.PERSON2 = p.NAME WHERE r.PERSON2 = p.ID_NUMBER; and nothing happened. Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/ Share on other sites More sharing options...
Adam Posted December 21, 2010 Share Posted December 21, 2010 Why are you actually updating this table in the first place? You should store the user's ID in a table like that, not data that could possibly change in the future. Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1149834 Share on other sites More sharing options...
Zojak_Quaguz Posted December 21, 2010 Author Share Posted December 21, 2010 I know, but that's what I was asked to do Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1149893 Share on other sites More sharing options...
Adam Posted December 21, 2010 Share Posted December 21, 2010 Fair enough. Is an error returned, or is the affected rows just 0? Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1149895 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2010 Share Posted December 21, 2010 Your second query works for me. I recommend that you try again and if necessary fetch the actual table contents after you execute the query to see the changes. Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1149897 Share on other sites More sharing options...
Zojak_Quaguz Posted December 22, 2010 Author Share Posted December 22, 2010 MrAdam: Affected rows 0. PFMaBiSmAd: Weird. I did that, and the second row showed up as NULL just as before. Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1150346 Share on other sites More sharing options...
PFMaBiSmAd Posted December 22, 2010 Share Posted December 22, 2010 You would need to show us what result you are seeing in front of you for anyone to be able to help with it. Best guess is some of your data values contain white-space/non-printing characters and the query does not match them. Quote Link to comment https://forums.phpfreaks.com/topic/222274-update-multiple-columns/#findComment-1150394 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.