SQL query to list all WordPress post revisions for archiving

Here's the SQL query to get all post revisions, which I do prior to cleaning them out of the database, which seems to make it much faster:

SELECT p.*
FROM [posts table name] p
WHERE (p.post_type = 'post' OR p.post_type = 'page') -- Include posts/pages
AND (p.post_date BETWEEN '2020-01-01' AND '2029-07-01') -- Adjust date range
OR (p.post_type = 'revision' AND p.post_parent IN (
SELECT ID FROM [posts table name]
WHERE post_date BETWEEN '2024-01-01' AND '2024-07-01'
));

To get just a count of revisions, change SELECT p.* to SELECT count(*).