I want to build a small task-application with MYSQL and PHP. I want to assign tasks to single users and to multiple user groups. I was thinking to have a user_table:
userid name
1 Peter
2 Hans
usergroup_table
usergroup_id name
1 Usergroup 1
2 Usergroup 2
usergroupmap_table (2 shared primary keys)
usergroup_id userid
1 1
1 2
tasks_table
taskid taskname due_date
1 Finish my exams 10-06-2016
2 Another task 2 do 15-06-2016
From this it is easy. Now I can think of 3 ways how to assign the user and usergroups to tasks. But I can't choose which one is best (Normalization??)
Solution 1
two seperate table, one table with single users, and the other with assigned groups: usertask_table (2 shared primary keys) && usergroup_table
taskid userid
1 1
1 1
taskid groupid
1 1
2 1
Solution 2
A combined table with either the userid 0, or groupid 0:
taskid groupid userid
1 1 0
2 1 0
2 0 1
2 0 2
Solution 3
A combined table with all assigned tasks, but with a varchar to define which group is selected
taskid type id
1 group 1
1 group 2
2 user 1
2 user 2
I have no idea which solution gives me the most optimal design. I want to extend this application also with some other tables, where at the same way user and group permissions need to be assigned. Now i'm thinking about the 3th solution...