I have a discussion forum that I would like to filter approved posts. I would like to know how to select the max(datetime) but only if the max has an approved value of 1. The only way I can think to do this is adding a where clause of approved = 1 but this will not work with a group by. Any suggestions?
select * from questions where datetime in (select max(datetime) from questions group by id )
SELECT questions.*
FROM ( SELECT id
, MAX(datetime) AS max_datetime
FROM questions
WHERE approved = 1
GROUP
BY id ) AS m
INNER
JOIN questions
ON questions.id = m.id
AND questions.datetime = m.max_datetime