By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Quickly adding text to a mysql text field that is NOT empty

P: n/a
Hi all

Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Please help!

Feb 5 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I could have sworn I already replied to this but it appears that it did
not go through, but anyway; you want to modify the contents of an
existing field without having to fetch it using a query, yes? This is
possible through the use of MySQL's CONCAT() function:

UPDATE `my_table` SET `my_field` = CONACT(`my_field`, ' append this');

So, for example the value of 'my_field' is 'John'. Upon running the
query the value of 'my_field' will become 'John append this'. Hope that
helps.

Feb 5 '06 #2

P: n/a
So basically you want to append a string or data to existing data in a
field without having to fetch the contents of that field first? Yeah,
that's possible:

UPDATE `my_table` SET `myfield` = CONCAT(`myfield`, 'newvalue');

So say the value of 'myfield' was 'John' and I ran that query, the
value of 'myfield would now be 'Johnnewvalue'. Is that what you wanted?

Feb 5 '06 #3

P: n/a
So say the value of 'myfield' was 'John' and I ran that query, the
value of 'myfield would now be 'Johnnewvalue'. Is that what you wanted?


Thanks for your help xcla, the problem I have is that I don't know what
is in the first part of the string, so i need a query which adds to the
data that is in there without me defining it.

Feb 5 '06 #4

P: n/a
Yeah I've got it working now thanks!

Feb 5 '06 #5

P: n/a
You're very welcome, I used 'John' as an example, just specifying the
field name works as I assume you've already found out. Glad I could
help!

Feb 5 '06 #6

P: n/a

<xc*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I could have sworn I already replied to this but it appears that it did
not go through, but anyway; you want to modify the contents of an
existing field without having to fetch it using a query, yes? This is
possible through the use of MySQL's CONCAT() function:

UPDATE `my_table` SET `my_field` = CONACT(`my_field`, ' append this');
you mean CONCAT

So, for example the value of 'my_field' is 'John'. Upon running the
query the value of 'my_field' will become 'John append this'. Hope that
helps.

Feb 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.