Skip to content

Instantly share code, notes, and snippets.

@agarman
Created July 7, 2022 17:10
Show Gist options
  • Save agarman/d7952471d885681fbc5aa854f47f954d to your computer and use it in GitHub Desktop.
Save agarman/d7952471d885681fbc5aa854f47f954d to your computer and use it in GitHub Desktop.
MySQL SELECT RAND() rows FAST
SELECT
*
FROM {{db}}.{{nm}}
WHERE
rand() < 0.1
AND UPDATED_TIMESTAMP BETWEEN CURRENT_DATE() - 7 AND DATE_SUB(CURRENT_TIME(), INTERVAL 2 HOUR)
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment