For the following query I get the error This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
SELECT * FROM `wp_dash_competition_versions` _versions
WHERE DATEDIFF(CURRENT_TIMESTAMP, _versions.created_at) > 20 AND
id NOT IN (
SELECT id FROM `wp_dash_competition_versions` WHERE competition_id = _versions.competition_id
ORDER BY created_at LIMIT 5
)
Other SO articles recommend the use of a join, however the join query doesn't apply the limit to a given parent_id.
Is it possible to achieve a single query that selects rows from a child table skipping the first 5 rows for a given parent_id?
I'm developing the query primarily for a delete operation to prune the table. I need the select first to ensure the statement is correct.
CREATE TABLE `wp_dash_competition_versions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`competition_id` bigint(20) unsigned DEFAULT NULL,
`competition_serialised` mediumtext COLLATE utf8mb4_unicode_520_ci,
`created_user_id` bigint(20) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)