moi
moi

Reputation: 45

How to update sqlite row with concatenate existing values in row with a new value

I would like to add a value (concatenate) at the end of existing values in a column of sqlite table. ie: the column contains : banana, orange, pear, pinapple I want to add lemon at the end of the column to have : banana, orange, pear, pinapple, lemon

Upvotes: 2

Views: 817

Answers (2)

forpas
forpas

Reputation: 164089

Use the concatenation operator || in the update statement:

update tablename
set columnname = columnname || ', lemon'
where columnname = 'banana, orange, pear, pinapple'

or:

where <some other condition>   

Replace tablename and columnname with your table's and column's names.
If you want to update all the rows of the table remove the where clause.

Upvotes: 2

Dennis Proksch
Dennis Proksch

Reputation: 260

Is perhaps this answer here at SO the right one?

So in a table "groceries" with a column fruits "banana, orange" like

SELECT fruits || ', lemon' FROM groceries

this would yield

banana, orange, lemon

Upvotes: 0

Related Questions