select t.id,
t.title,
count(*) count_comments
from topics t
left join comments c on c.topic_id = t.id
left join topics_views v on v.topic_id = t.id
where (v.user_id = ?
and c.date_added > v.date_last_view) or v.date_last_view is null
group by t.id,
t.title