SELECT TOP 1000 * FROM PostsWithDeleted TABLESAMPLE (10 P...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Web Applications Meta

Q&A about the site for power users of web applications

-- Get 1000 random posts from the last year
-- Using TABLESAMPLE for better performance on large datasets
-- Filtering for non-deleted posts from last year
SELECT TOP 1000
    *
FROM PostsWithDeleted
TABLESAMPLE (10 PERCENT)  -- Adjust percentage based on table size
WHERE 
    CreationDate >= DATEADD(year, -1, GETDATE())
    AND CreationDate <= GETDATE()
    AND DeletionDate IS NOT NULL  -- Only non-deleted posts
ORDER BY NEWID()  -- Random ordering

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results