14

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..

Aravindhan
  • 3,566
  • 7
  • 26
  • 42
  • 1
    You only want to do for a specific row or all the rows .. ? – AurA Dec 18 '12 at 04:27
  • 2
    possible duplicate of [How to prepend a string to a column value in MySQL?](http://stackoverflow.com/questions/680801/how-to-prepend-a-string-to-a-column-value-in-mysql) – magdmartin Oct 29 '13 at 18:37
  • duplicate of http://stackoverflow.com/questions/2761583/appending-data-to-a-mysql-database-field-that-already-has-data-in-it – qdinar Apr 09 '17 at 15:26

2 Answers2

37

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

Dhinakar
  • 4,061
  • 6
  • 36
  • 68
18

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;
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
  • 2
    +1 for quick answer. But this will add `d` to that specific column in all row and OP doesn't mentioned this – xkeshav Dec 18 '12 at 04:28
  • 1
    @diEcho I updated my answer. But the question is lack more information about what exactly the OP is trying to do. – Mahmoud Gamal Dec 18 '12 at 04:32