Working with MySQL 5.7, and I have this query:
SELECT
COUNT(`email`) as 'EMAIL COUNT'
, `email`
,`isp_group`
, GROUP_CONCAT(`list_id`) AS 'Lists'
FROM `table`
WHERE `status` = 'ACTIVE' AND `last_sent_date` BETWEEN CURDATE() - INTERVAL 30 DAY AND
CURDATE()
GROUP BY `email`, `isp_group` HAVING COUNT(`email`) > 2
ORDER BY `EMAIL COUNT` DESC
Basically this query returns records that are on 2 or more lists, which is over 250k records.
I want to delete these records.
So I tried this:
DELETE FROM `table` WHERE
(SELECT
COUNT(`email`) as 'EMAIL COUNT'
, `email`
,`isp_group`
, GROUP_CONCAT(`list_id`) AS 'Lists'
FROM `table`
WHERE `status` = 'ACTIVE' AND `last_sent_date` BETWEEN CURDATE() - INTERVAL 30 DAY AND
CURDATE()
GROUP BY `email`, `isp_group` HAVING COUNT(`email`) > 2
ORDER BY `EMAIL COUNT` DESC)
But the error I’m getting says, “Operand should contain 1 column(s)”.
I removed the COUNT('email') as 'EMAIL COUNT'
and the ORDER BY EMAIL COUNT DESC
from the inner select, but I’m still getting the same error.
How can I write this to make it work?