select *
from dialog_users as d1
where
user_id = 1 -- первый юзер
and
(select dialog_id
from dialog_users as d2
where d2.user_id = 2 -- второй юзер
and d2.dialog_id = d1.dialog_id)
and
(select count(*)
from dialog_users as d3
where d3.dialog_id = d1.dialog_id) = 2 -- количество человек в диалоге