Skip to content

Instantly share code, notes, and snippets.

@fillest
Last active December 22, 2015 06:09
Show Gist options
  • Save fillest/6428976 to your computer and use it in GitHub Desktop.
Save fillest/6428976 to your computer and use it in GitHub Desktop.
SELECT e.source_id, COUNT(e.*)
FROM entries AS e
INNER JOIN users__sources AS sassoc
ON sassoc.source_id = e.source_id AND sassoc.user_id = :user_id
LEFT JOIN users__entries AS eassoc
ON eassoc.entry_id = e.id AND eassoc.user_id = :user_id
WHERE eassoc.entry_id IS NULL OR eassoc.is_read = FALSE
GROUP BY e.source_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment