Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql append column value

Tags:

mysql

I am having the table with the following structure

      ----------------------------
       id                  content
      ---------------------------
        1                   abc
        2                   bca
      ---------------------------

I want to append the character 'd' with the field 'content' ... So i want the table structure as follows

       ----------------------------
       id                  content
      ---------------------------
        1                   abcd
        2                   bca
      ---------------------------

How can i do this..

like image 968
Aravindhan Avatar asked Dec 18 '12 04:12

Aravindhan


People also ask

How do I append a column in MySQL?

You can append data to a MySQL database field with the help of in-built CONCAT() function. Here is the query to append the data ”Taylor” to the data already in the column. Therefore, the data will get appended.

How can I append a string to an existing field in MySQL?

To prepend a string to a column value in MySQL, we can use the function CONCAT. The CONCAT function can be used with UPDATE statement.

How do I update a column in MySQL?

The syntax to modify a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name MODIFY column_name column_definition [ FIRST | AFTER column_name ]; table_name. The name of the table to modify.

How do you append data in SQL?

On the Home tab, in the View group, click View, and then click Design View. On the Design tab, in the Query Type group, click Append. The Append dialog box appears. Next, you specify whether to append records to a table in the current database, or to a table in a different database.


2 Answers

If you want update the column from the Table then use below Query

update table1 set content = concat(content,'d');

If you want to select the column concatenation with 'd; the use below Query

select id, concat(content,'d') as content from table1;

Refer :

http://sqlfiddle.com/#!2/099c8/1

like image 112
Dhinakar Avatar answered Oct 11 '22 12:10

Dhinakar


You can use the CONCAT, like so

SELECT 
  id,
  CONCAT(content, 'd') content
FROM tablename;

You can also specify a WHERE clause to determine which rows to update. Something like:

SELECT 
  id,
  CONCAT(content, 'd') content
FROM tablename
WHERE id = 1;
like image 29
Mahmoud Gamal Avatar answered Oct 11 '22 13:10

Mahmoud Gamal