Je ne connais pas du tout le SQL… mais serait-il possible d’avoir une requête qui me montre les sujets où j’ai été mentionné… mais où je n’ai pas répondu après avoir été mentionné (j’imagine que cette partie est délicate, si c’est même possible) ?
sujets où l’utilisateur a été mentionné et n’a pas répondu après avoir été mentionné
-- [params]
-- user_id :user
WITH mentions AS (
SELECT target_topic_id, target_post_id, created_at
FROM user_actions
WHERE action_type = 7 -- mentions
AND user_id = :user
), replies AS (
SELECT topic_id, MAX(created_at) created_at
FROM posts
WHERE user_id = :user
AND deleted_at IS NULL
AND post_type IN (1, 4) -- régulier OU whisper
GROUP BY topic_id
)
SELECT DATE(m.created_at) mentionné_le, target_post_id post_id
FROM mentions m
LEFT JOIN replies r ON r.topic_id = m.target_topic_id
JOIN topics t ON t.id = m.target_topic_id
WHERE m.created_at > COALESCE(r.created_at, '1900-01-01')
AND t.deleted_at IS NULL
AND NOT t.archived
AND NOT t.closed
ORDER BY m.created_at DESC