Eric Bellamy Eric Bellamy - 2 months ago 7
MySQL Question

How to store multiple users in a MySQL table row

What I have is a program that allows users to monitor posts by specifying what they are looking for. I'm predicting that many users will monitor the same posts, and would like to instead of having them all listed as separate posts, have all of the users grouped into the same row.

I'm unsure of wether MySQL has a way to point to multiple users in a different table, or some other way of doing it. I've seen things such as joining mentioned, but have not seen any ways to implement it in the way that I would like.

What i'm wondering if it's possible to do:

Table 1: Table 2:

Platform Post Name Users Users
----------------------------------- ----------------
PC Title [ ] ----------> Jane
|---> Bob
|---> Roger

Is it possible to do this, or what way should I be going about this?


Putting user names in a comma-separated list is a terrible solution. Please don't do that. It leads to all sorts of problems.

The best way to do this is to create a new table with two columns: USER_ID and POST_ID. Whenever a user wants to monitor a post, add a row with the user's ID and the post's ID.