faisal
faisal

Reputation: 475

multiple value stored in single coloumn in MySQL database?

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.

Upvotes: 1

Views: 1630

Answers (3)

gameover
gameover

Reputation: 12051

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.

Upvotes: 6

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124868

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.

Upvotes: 1

Jasperdc
Jasperdc

Reputation: 83

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.

Upvotes: 2

Related Questions