create a table inside a column in MYSQL

2019-06-08 16:03发布

Apologies if I am mistaken, but is there any way to create a table inside a column in MySql?

Brief: I have a table named test_table which contains a column named name test_column. Now I want to create a table inside test_column. Is this possible?

Thanks In advance

4条回答
姐就是有狂的资本
2楼-- · 2019-06-08 16:32

That approach is not possible. What you are looking for is a second table that is linked using a field in the first table.

Example:

test_table:

ID | column1 | some more columns

test_table2:

table1_ID | column1| column2...

You can then access them using JOIN commands. For example:

SELECT *
FROM test_table t1
INNER JOIN test_table2 t2
ON t1.ID = t2.table1_ID

This way you can have multiple rows for each ID in table 1, which has the effect you are looking for.

查看更多
相关推荐>>
3楼-- · 2019-06-08 16:41

No nested tables in MySql, but there is a SET datatype that you can use in a table
http://dev.mysql.com/doc/refman/5.0/en/set.html

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-06-08 16:55

This is not possible in MySQL.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-06-08 16:57

You would create a "child" table with an id that is referenced in the column of the main table. You wouldn't create a "table" in a column.

For example

Table 1
columm_pk int
column_fk int

table 2
column_pk (this is what goes in table 1)
other columns as needed. 

then you just join the tables based on that fk id. You can have multiple fk column in the first table that link to different child tables. You can also look in to SET data types in MySql although I wouldn't recommend them.

btw, If your question is MySql specific then you shouldn't use the oracle tags.

查看更多
登录 后发表回答