Can anyone please help me with an SQL query which will allow me to populate the real_name column in table 1 with values from both first_name and second_name columns in table 2 by referencing the usernames.
TABLE 1
audit_username | real_name |
---|---|
AHolland | |
THardy | |
LGentle | |
BGreen |
TABLE 2
second_name | first_name | username |
---|---|---|
Holland | Andrew | AHolland |
Hardy | Tom | THardy |
Gentle | Lauren | LGentle |
Green | Barry | BGreen |
2
Answers
How about
You can use an UPDATE statement with a JOIN to achieve this. Here’s an example of how you can do it:
This SQL query will join
table1
andtable2
on theusername
field, and then update thereal_name
field intable1
with thefirst_name
andsecond_name
fields fromtable2
, separated by a space.