@ZygD, Here's the diagram:
USER user_id int primary key auto_increment user_name varchar(100) password varchar(100) GROUP group_id int primary key auto_increment group_name varchar(100) DATA data_id int primary key auto_increment data_name varchar(100) USER_GROUP user_id int group_id int GROUP_DATA group_id data_id
I will explain. First you define your "object types". You have USER, GROUP and what you called DATA. Also, it's probably nice to use another word instead of DATA. Use something like ITEM or even DATAITEM. In this example, I will use DATA. So, each of these tables has an integer value as a primary key. The primary key is a unique identifier for the entry in the table, and it automatically increases. You can install this in Access.
Now that you have three types of type tables, you need to call them “join tables” to describe the relationship between the “object type” tables. The USER_GROUP table indicates that a user can belong to one or more groups. For example, if User 1 belonged to both group 1 and group 2, then to describe these relations in the table USER_GROUP you must have two entries. The first line will be 1.1, and the second line will be 1.2.
The GROUP_DATA table describes the relationship between GROUP and DATA. For example, group 1 may have access to data 2 and data 3. Again, you will have two rows in the GROUP_DATA table to describe these relationships. The first line will be 1.2, and the second will be 1.3.
Now, since User 1 belongs to group 1, user 1 will have access to data 2 and 3. Then your SQL is simplified:
// Authenticate the user with user_name and password: select @user_id = a.user_id from user a where a.user_name = @user_name and a.password = @password // Get DATA by user_id select c.data_id, c.data_name from user a join group b on a.user_id = b.user_id join data c on b.data_id = c.data_id where a.user_id = @user_id
source share