To preface this question I should say I know very little about database efficiency which will become glaringly apparent very shortly.
This is a fairly simple question:
I’d like to store attendance to events within a mysql database.
I’ve thought of two possible methods (there are more, I’m sure):
- Create an additional
attendancerow in theeventstable, containing a comma separated list of user ids - Create an
attendancetable, containing two columns,event_idanduser_id
My instinct says that method 2 would be the most efficient — although multiple rows would have to be returned and traversed, this is likely less costly than searching for a particular user_id within a concatinated string…
Can anyone confirm this?
The second option is better. Searching in a comma separated string is time consuming.
However in the 2nd option, make sure the
event_idand theuser_idareFOREIGN KEYS.This will
INDEXthe columns and you will have better searching results.