I have two columns in one table. I have created a third column in that same table and I want to concatenates both columns into the third. For example, I have two columns, first_name and last_name. The third column is titled full_name. What would I write as a sql query to combine first_name and last_name to combine and insert into full_name. Also, I want to concatenate a space between both columns when being inserted into full_name.
Use CONCAT()
:
UPDATE tbl
SET full_name = CONCAT(first_name, ' ', last_name)
If either first_name or last_name can contain NULL
values, you'll want to do:
UPDATE tbl
SET full_name = CONCAT(IFNULL(first_name, ''), ' ', IFNULL(last_name, ''))
So as to prevent a NULL
value being returned when just one of the parameters to CONCAT
is NULL.
Assuming you are using Oracle:
update your_table
set full_name = first_name || ' ' || last_name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.