0

I have searched different pages. Is it possible to insert many values in single cell

enter image description here

Under id 475 can all values be stored like related_id=281,283,284,285,286

INSERT INTO LOGI (related_id)VALUES(281), (283), (284), (285), (286) 

UPDATE1 Now if I want to update the all logi_keyword_id for logiid=613Update issue UPDATE logi_logi_keyword SET logi_keyword_id='102' WHERE EXISTS logi_id='543' but it gives error- #1062 - Duplicate entry '543-102' for key 'PRIMARY'

1
  • you should not do it. you should use another table. Commented Jan 16, 2014 at 15:05

2 Answers 2

3

Sure if you really want to, assuming related_id is a varchar or text column type...

INSERT INTO LOGI (related_id) VALUES('281,283,284,285,286'); 

However this breaks the whole foreign key paradigm. You won't be able to run SELECT queries and join tables based on this column.

Better to create a cross-reference table. Call it LOGI_RELATED perhaps, with logi_id and related_id columns. Then you can have one LOGI record with relationships to multiple RELATED records.

Sounds like you may want to do some research on "many to many relationships" and improve your database design.

Sign up to request clarification or add additional context in comments.

8 Comments

@Hanky웃Panky I see OP asking to "insert many values in single cell." All "under id 475." That doesn't sound like multiple rows to me.
But taking a look at the problem image link they gave, you'll notice its the other way. They have a new row for every value
@Hanky웃Panky That image is the problem, not how he wants it. He wants all these values "under id 475" which is a single row.
Fair enough, that makes sense.
@jszobody you can store like this and use the explode and implode functions to get the data and merge it, but its preferable to store them in a different table with uid and related_id as two columns with foreign key on uid
|
0

for this situation you need another table to establish a one to many relation using your table id as a foreign key.
something like this:

Another table

id | your_table_id | related_id

1 | 475 | value

2 | 475 | another_value

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.