thank_you
thank_you

Reputation: 11107

Two columns into one on same table

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.

Upvotes: 0

Views: 2622

Answers (2)

Zane Bien
Zane Bien

Reputation: 23125

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.

Upvotes: 2

Phan
Phan

Reputation: 114

Assuming you are using Oracle:

update your_table
   set full_name = first_name || ' ' || last_name

Upvotes: 0

Related Questions