-3

How can I add one value to the field in my table?

I update the field by below mysql, but it just update the value.

UPDATE table SET value= 3 WHERE id= 1

So here is my actual want to do:

Before I add value

+--------------+
| table        |
+--------------+
| id   | value |
+--------------+
| 1    | 1     |
+--------------+
| 2    | 2     |
+--------------+

After I add value

+-------------------+
| table             |
+-------------------+
| id   | value      |
+-------------------+
| 1    | 1 , 3      |
+-------------------+
| 2    | 2          |
+-------------------+
Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
userzero
  • 109
  • 5
  • 16

2 Answers2

2

It seems you are using an integer field for 'value' column, you can't store more than one number in one integer field, what you might do it's set both 'id' and 'value' columns as primary keys so you will be able to insert more than one value for the same id. If that's not what you want, consider using the 'SET' type. For more info https://dev.mysql.com/doc/refman/5.0/en/set.html

lucasrod
  • 93
  • 1
  • 12
  • 1
    The first suggestion, using a composite key, is the way to approach this. You should have a row for each value to maintain normalization. – Devon Bessemer Apr 26 '15 at 04:28
0

I have a feeling it's not, but if that is literally what you want to happen...

UPDATE table SET value=CONCAT(value, ' , ', 3) WHERE id=1
Jason Byrne
  • 1,579
  • 9
  • 19