mysql - Update Query when username changes -


here query i'm trying. please don't laugh i'm clueless, lol.

update toondb set tusername = (select username user userid='1') (select username user userid='1') != (select tusername toondb tuserid= '1') 

i whipped up, hoping it'd work. let me try explain, please.

i have 1 table called 'toondb'. toondb has different columns. in particular case, focusing on 'tusername' , 'tuserid' column in table.
'tusername' column contains user's username, , 'tuserid' column contains user's userid. when submit info via form, 'tusername' , 'tuserid' columns automatically populated username , userid on forum.

now, other table, 'user', info comes from. there column 'userid' , 'username' in 'user' table.
userid 1 , username whatever

so.. have row in 'toondb' table myself. userid set 1 row (as userid never changes). however, username set 'admin'.

well, since new username 'whatever' , it's not 'admin' anymore, need have query can set automatically run check 'toondb' make everyone's userid matches tusername.

e.g. checks toondb table sees userid 1 sees username set 'admin' checks user table sees userid 1 sees username set 'whatever' update's toondb change tusername 'whatever' userid '1'.

thanks if can help.. sorry if confusing.. tried make sound not confusing lol. know basic mysql can ask stupid questions sometimes.. ;(

just clarify.. 'tusername' , 'tuserid' columns in toondb table 'username' , 'userid' columns in user table values in user table accurate. value in column 'username' in user table must populate value in 'tusername' column in toondb table recent info. yeah. :)

as commented, should avoid having username in both tables, if necessary, can use triggers update usernames when changed


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -