SQL - Update without losing values

Asked

Viewed 1,180 times

0

Good personal my doubt is the following I would like to update a value in the "Database" without losing the value there already allocated, Good for better understanding of my doubt I would quote an example: I have a TABLE CALLED: Clients ; With columns: name, age, phrase.

I have the following data there > old phrase name Lucas 20 good

I would like to update the sentence without losing what is already in it:

UPDATE Clientes
SET frase='dia'
WHERE nome='lucas';

In other words, I would like him not to change the phrase to "day" but to concatenate, I wanted it to be> bomdia. It updates keeping the value it already has there. Thanks in advance.

  • 3

    SET frase= frase +'dia' ?

  • 1

    http://answall.com/q/43907/101

  • @rray in the case of integers, could put SET cont = cont + '1' who would act as an accountant?

  • I have tried this way but it does not work, it assigns 0. Yes Ivcs if it is the type int you doing this way it makes the sum and assigns without problems, It is a pity that in varchar type it does not concatenate :( .

  • Has Concat also.

  • @A more trivial way would be to write a query for the sentence column before the update, after that concatenate.

  • Yes I already thought about it, however this way I would have to perform 2 queries, I want to do something more practical just a light concatenation, Got it?

Show 2 more comments

1 answer

2


Using the CONCAT function you achieve this.

UPDATE Clientes SET frase = CONCAT(frase, 'dia') WHERE nome='lucas';

Functional example here.

  • 2

    Thank you dear, I had found the same example on a page here at Overflow, I would already post here for the rsrs people, but as you posted first is great, Thanks for the help!. WORKING PERFECTLY!.

  • Don’t forget to mark the answer as valid, so make it easier for those who search.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.