SELECT dialogs_users.* FROM dialogs_users
LEFT JOIN dialogs ON dialogs.id = dialogs_users."dialogId"
WHERE
dialogs.type = 'personal'
AND
dialogs_users."userId" IN ('69e56a68-edbd-4f8b-8ccd-cb8031c5c865', '06b475b7-8f12-4879-bea4-e8f22ef85a46')
AND
dialogs_users."dialogId" IN (SELECT dialogs_users."dialogId" dialogId FROM dialogs_users GROUP BY dialogId HAVING COUNT(*) > 1);
SELECT
du.userId
FROM
dialogs_users du
INNER JOIN dialogs d
ON du.dialogId = d.id
WHERE
d.type = 'personal' AND du.dialogId = $dialogId