Skip to content

Instantly share code, notes, and snippets.

@llamapope
Created August 11, 2010 18:16
Show Gist options
  • Save llamapope/519433 to your computer and use it in GitHub Desktop.
Save llamapope/519433 to your computer and use it in GitHub Desktop.
/*
* The TOP value is the page count, the inner TOP value is where to start from.
* All where and ORDER BY statements need to be the same
*/
SELECT TOP 50
id, lastAction, userAgent, sessionStartedAt, sessionEndedAt,
/* optionally get the total count for the filtered set */
(
SELECT COUNT(id)
FROM tbl_session_logs
WHERE userAgent LIKE '%Firefox%'
) AS totalRecords
FROM tbl_session_logs
WHERE id NOT IN
(
SELECT TOP 50 id FROM tbl_session_logs
WHERE userAgent LIKE '%Firefox%'
ORDER BY id desc
)
AND userAgent LIKE '%Firefox%'
ORDER BY id desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment