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 […]
In a previous blog post, we’ve advertised the use of SQL EXISTS rather than COUNT(*) to check for existence of a value in SQL. I.e. to check if in the Sakila database, actors called WAHLBERG have played in any films, instead of: SELECT count(*) FROM actor a JOIN film_actor fa USING (actor_id) WHERE a.last_name = […]
In MySQL, you cannot do this: create table t (i int primary key, j int); insert into t values (1, 1); update t set j = (select max(j) from t) + 1; The UPDATE statement will raise an error as follows: SQL Error [1093] [HY000]: You can’t specify target table ‘t’ for update in FROM […]