Skip to content

Instantly share code, notes, and snippets.

@sajadshafizadeh
Created April 6, 2018 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajadshafizadeh/b52b3636033ad0b419d156919de16a3b to your computer and use it in GitHub Desktop.
Save sajadshafizadeh/b52b3636033ad0b419d156919de16a3b to your computer and use it in GitHub Desktop.
SELECT n.id, <getting the smallest id of those 15 groups> AS smallest_id
FROM notifications
WHERE author_id = ? AND id >= smallest_id
ORDER BY id DESC;
<Smallest id> would be something like that: (it should be just one id, not a set of ids)
SELECT MIN(id)
FROM notifications
WHERE author_id = ?
GROUP BY post_id, title, content, date_time
ORDER BY id DESC
LIMIT 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment