@lottie
In a MySQL column, you can store multiple values by using one of the following approaches:
Example:
1 2 3 4 5 |
id | name | colors --------------------------------------- 1 | Apple | red, green, yellow 2 | Banana | yellow 3 | Orange | orange, yellow |
Example:
1 2 3 4 5 |
id | name | colors --------------------------------------- 1 | Apple | ["red", "green", "yellow"] 2 | Banana | ["yellow"] 3 | Orange | ["orange", "yellow"] |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Table: Fruits id | name --------------- 1 | Apple 2 | Banana 3 | Orange Table: Colors id | color --------------- 1 | red 2 | green 3 | yellow 4 | orange Table: Fruit_Colors fruit_id | color_id --------------------- 1 | 1 1 | 2 1 | 3 2 | 3 3 | 3 3 | 4 |
In this example, the Fruit_Colors
table represents the relationship between fruits and colors. Each row in the junction table represents a connection between a specific fruit and a specific color.