/*Table structure for table `tbl_accounts` */
CREATE TABLE `tbl_accounts` (
`account_id` int(11) NOT NULL AUTO_INCREMENT,
`account_name` varchar(50) DEFAULT NULL,
`username` varchar(50) DEFAULT NULL,
PRIMARY KEY (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*Data for the table `tbl_accounts` */
insert into `tbl_accounts`(`account_id`,`account_name`,`username`) values
(1,'CASH-USER1','user1'),
(2,'CASH-USER2','user2'),
(3,'BANK-USER1','user1');
/*Table structure for table `tbl_account_share` */
CREATE TABLE `tbl_account_share` (
`share_id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) DEFAULT NULL,
`shared_with` varchar(50) DEFAULT NULL,
`share_permission` varchar(50) DEFAULT NULL,
PRIMARY KEY (`share_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*Data for the table `tbl_account_share` */
insert into `tbl_account_share`(`share_id`,`account_id`,`shared_with`,`share_permission`) values
(1,1,'user2','F');
in addition to the above i have another table tbl_transactions which stores the transactions pertaining to the relevant accounts. tbl_accounts is the master table and account_id is the foreign key in the tbl_transactions. user2 should have access to the transactions pertaining to account 1
CREATE TABLE `tbl_transactions` (
`trans_id` int(11) NOT NULL AUTO_INCREMENT,
`trans_date` datetime DEFAULT current_timestamp(),
`trans_remarks` varchar(50) DEFAULT NULL,
`account_id` int(11) DEFAULT NULL,
`amount` float DEFAULT NULL,
`username` varchar(50) DEFAULT NULL,
PRIMARY KEY (`trans_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*Data for the table `tbl_transactions` */
insert into `tbl_transactions`(`trans_id`,`trans_date`,`trans_remarks`,`account_id`,`amount`,`username`) values
(1,'2021-12-15 04:57:22','TEST1',1,100,'user1'),
(2,'2021-12-15 04:57:22','TEST2',2,50,'user2'),
(3,'2021-12-15 04:57:45','TEST3',3,10,'user1');
There are three accounts in tbl_accounts. account with id 1 and 3 belongs to user1 and account with id 2 belongs to user2username is the userid field set in the Advanced Security. Only user1 can access the account with id 1 and 3.I want to share the account with account id 1 belonging to user1 to user2 with restricted permissions which is defined in share_permission. However account id 3 should not be accessible to user2.