views:

320

answers:

3

Hi all developers, How can i store multiple values in one attribute. for example: column name: telephone i want to store 5,7 and 16 this three different values in one column (telephone) in one row.

+2  A: 

You could separate the different values by a "," or ";"? When you query the content, just split the string on the delimiter....

Otherwise I don't think this is possible.

Jasperdc
+1  A: 

By separating them with commas, for example? Be advised that this is not recommended, if you need multiple values for the same column, you need multiple rows, or preferably an auxiliary table to hold all phone numbers.

But you can just do INSERT INTO table SET telephone = '5,7,16' if that column is VARCHAR or some other string form. Splitting the values back to separate entries is harder and you usually have to do that in your program code.

Tatu Ulmanen
+6  A: 

You should not be doing that. It goes to show that the DB has not been designed properly.

But if you have to do it without altering your DB design. You can join all the telephone numbers with a special glue, which is ensured not to be part of any telephone number, something like %. So 5, 7 and 16 will all be stored in one column of type varchar as 5%7%16, later your application and split them up as needed.

gameover
+1 for pointing out that this **should not be done** .. but providing an answer anyhow.
lexu