SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

concat: Adding string at the end of a field data


We can append a string or data to an existing data of a field by using concat function of MySQL. Here we are not updating or replacing an existing data with new one, we are just adding the string at the end of the field data.

For example we want to add site signature at the end of the comments posted by users. Here each user posts are different so we can't apply any update command so we will use concat to add the site signature to the each post kept inside a record – field in our update command.

Here is the syntax

concat(field_name,"string to add")

Now let us see how it is used in a MySQL table query.

update photo_img set dtl=concat(dtl,'site_data to add') where gal_id='22'

The above command will add the string site_data to add at the end of each record dtl field for which gal_id is equal to 22

Further readings
Update SQL commands
Updating another table with data from main table
Replace SQL to update part of the data of a field
concat: Appending string at the end of a field data
Creating a new table by using data from one table
Copying data from one table to another table
Inserting SUM, AVG data from one table column to other using group by command
mroz06-02-2009
I tried but it didn't work. Which version of MySQL did you try? Mine is 4.2
smo06-02-2009
What is the error message you are getting?
Are you getting message saying function concat does not exit ?
Ramya06-11-2009
it did work but not in the way i wanted.It was wacky it updated by id field.I mentioned the column name and string to append and but it updated by id field. i have no idea.
Jim19-01-2010
This only works if the value of the field is not NULL.... FYI ;)
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
SQL Tutorial List
SQL Commands
SQL Sections
Date & Time
Join Table
String
Math
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.