0

I have a comma delimited list like this saved in a mysql table:

-----------------
|id | list      |
-----------------
| 4 |12,45,65,4 |

Each number in "list" corresponds with an ID in another table.

Is there a way so I can query the other table based on theses IDs and bring up those rows associated with the numbers in "list"?

1

1 Answer 1

2

Not any efficient way with your current schema. The correct and most efficient way to do it is to change the schema to hold multiple rows like this:

-----------------
|id | list      |
-----------------
| 4 |    12     |
| 4 |    45     |
| 4 |    65     |
| 4 |     4     |

Then you use JOIN operations to connect 4 to every related row in your other table.

This is called database normalization and is a very important topic in database design. Relational database systems are built to handle just this types of problems in an efficient manner.

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

2 Comments

I thought so, looks like I'll have to restructure things slightly. Thanks for the input!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.