in

MySQL add a filter for MIN function using WHERE condition


I need have below query which returns the MIN(date) from the table, however i want to add a where condition to the query to select the dates only between 2021-01-01 and 2021-04-01.

SELECT MIN(file.date_received) as date
FROM `file`
JOIN `ref` ON `ref`.`r_id` = `file`.`r_id`
JOIN `screening` ON `screening`.`screen_id` = `ref`.`r_id`
WHERE `ref`.`out` = 4

When i add the below where condition to the query i get error called

Error Code: 1111. Invalid use of group function

SELECT MIN(file.date_received) as date
FROM `file`
JOIN `ref` ON `ref`.`r_id` = `file`.`r_id`
JOIN `screening` ON `screening`.`screen_id` = `ref`.`r_id`
WHERE `ref`.`out` = 4
AND  MIN(file.date_received)  > '2021-01-01' AND  MIN(file.date_received)  < '2021-04-01'



Source: https://stackoverflow.com/questions/70719920/mysql-add-a-filter-for-min-function-using-where-condition

Video Collections — For kids who like to watch same videos over and over again

A simple way to write re-usable features with React + Effector