Is there a way to store a set of players in a column in a SQL database?
I have an events table and I want to store all players who have entered that event in the table under a column named players
.
The entrants will all be from the users
table.
I have found the set attribute but this looks like you need to specify specific values which the set can contain. I know these at the moment, but in the future, the users
table is likely to change.
so I want to,
- add a column to the
events
table calledplayers
that contains a set ofusers
- this should be empty initially but then as players are entered into that event, they are added to the set.
- from the java side of things, when I read the data from the database, it will take the event and display the name and then show all the users who are in the
players
set.
Is this the way I should be doing it? or is there a better way? i.e storing the users in an event in a set, storing this in some way in the database, and then reading this data back into the set in java before displaying it?
I am thinking I can store the id
from the users
table as a foreign key so in the set it will for example have users 1,3,4,7 in the set of players. Then when I get that data back I can display the users name in the web app.
Thanks