开发者

creating a list in MySQL

开发者 https://www.devze.com 2023-01-24 19:06 出处:网络
I want to create a MySQL database with one column containing a list(variable in size for different entries). I also have to allow ent开发者_开发问答ries to be added to that list later.

I want to create a MySQL database with one column containing a list(variable in size for different entries). I also have to allow ent开发者_开发问答ries to be added to that list later. What is the way to do this ?


The way this is typically done is to create a separate column that groups the items together:

list_id, value
1, a
1, b
1, c

2, e
2, f

SELECT value FROM table WHERE list_id = 1 will return three rows: (a, b, c)

Adding a new value x into list_id 2 would be something like this:

INSERT INTO table VALUES(2, 'x')

0

精彩评论

暂无评论...
验证码 换一张
取 消