select
c.id
from
user u
join
recipient r
on (u.id = r.user_id)
join
conversation c
on (u.id = c.user_id or r.conversation_id = c.id)
where
u.username = 'okitsu';
index 考慮すると、or で join してるところはチューニングとして union all 使うほうが多そう。
select
c.id
from
user u
join
conversation c
on (u.id = c.user_id)
where
u.username = 'okitsu'
union all
select
c.id
from
user u
join
recipient r
on (u.id = r.user_id)
join
conversation c
on (r.conversation_id = c.id)
where
u.username = 'okitsu';