MYSQL - Add multiple users to a table column

Maybe it's because I don't understand how to search for the right verbiage, but I'm having difficulty understanding how to attach multiple users to a table with multiple columns.

Here is what I'm attempting to do:

table name: user   

   user_id    user_name
   1          abc
   2          xyz  
   3          pqr
   4          new  


table2 name : brackets

    id             user_id    bracket_name
    1              4,2        bracket_1
    2              4,3,1      bracket_2 
    3              2,1        bracket_3
    4              3,4,2      bracket_4

-- OR --

table name: user   

   user_id    user_name  brackets_id
   1          abc        2,3
   2          xyz        1,3,4
   3          pqr        2,4
   4          new        1,2,4


table2 name : brackets

    brackets_id    user_id    bracket_name
    1              4,2        bracket_1
    2              4,3,1      bracket_2 
    3              2,1        bracket_3
    4              3,4,2      bracket_4

I'm using nodejs and sequalize as my ORM and understand enough to read, write, delete and update to these tables, but when it comes to organizing my data, I'm completely lost!

Is it possible to add an array to MYSQL with the user ID's or the brackets that the user is allowed to access? The bracket are generated by a user and then they can invite their friends to join a bracket. Users can join multiple brackets and join other brackets as users.

Any guidance would be very helpful!

Answers


I think a Junction Table would simplify this for you: http://en.wikipedia.org/wiki/Junction_table

It would look something like:

table name: user   

user_id    user_name
1          abc       
2          xyz        
3          pqr        
4          new        


table2 name : brackets

brackets_id        bracket_name
1                  bracket_1
2                  bracket_2 
3                  bracket_3
4                  bracket_4

table3 your junction table:

user_id     brackets_id      
1           2
1           3
2           1
2           3
2           4

etc.etc.

Need Your Help

Scripting in C# - Portable Library for XNA and 360?

c# scripting xna xbox360

I'm just wondering if this is even possible; how to do non-complicated scripting within C#.

signal callback and pthread sync

c sockets serial-port pthreads signals

On my app I have a pthread running a while(1) that read a socket client and a serial callback function. My app receive messages from a serial (like /dev/ttyS0) and receive messages from socket. The