В моем примере 'user2' - это другой пользователь, 'user1' - это вы:
-- query should work in most RDBMS
SELECT A1.account,
AU1.role AS user_2_account_role,
U1.uname AS user_2_name
FROM @account AS A1
JOIN @account_users AS AU1 ON AU1.account_id = A1.id
JOIN @user AS U1 ON U1.id = AU1.user_id
WHERE EXISTS(
-- get accounts that are 'mine'
SELECT *
FROM @user AS U2
JOIN @account_users AS AU2 ON AU2.user_id = U2.id
WHERE U2.uname = 'user1' -- 'mine'
AND AU2.account_id = AU1.account_id
)
AND U1.uname = 'user2' -- other user
Пример данных, которые я подготовил в SQL Server:
-- sample data in SQL SERVER
DECLARE @user TABLE(uname VARCHAR(20), id INT);
INSERT INTO @user(uname, id)
VALUES('user1', 1),
('user2', 2),
('user3', 3),
('user4', 4);
DECLARE @account TABLE(account VARCHAR(20), id INT);
INSERT INTO @account(account, id)
VALUES('account1', 1),
('account2', 2),
('account3', 3),
('account4', 4);
DECLARE @account_users TABLE(account_id INT, user_id INT, role VARCHAR(10));
INSERT INTO @account_users(account_id, user_id, role)
VALUES(1, 1, 'user1_role'),
(1, 2, 'user2_role'),
(2, 1, 'user1_role'),
(3, 3, 'user3_role'),
(3, 4, 'user4_role');