Forum Post
Index > Website > Stupid MySQL Bug

Author/Date Stupid MySQL Bug
fret
13/09/2005 2:29am
I noticed that all the threads we're being sorted against the date of the first post instead of the date of the last post. So I thought I'd go a fix it.

Turns out there is a pretty major bug in MySQL, where if you have some sql like:
select ParentPost, MAX(Date)
from forum_post
where forumid=2
group by ParentPost
order by date desc


The "MAX" function evaluates just one record, instead of the whole group created by the "group by" part of the command. If I take out the "where forumid=2" it starts to work. But I have to filter the results in PHP code afterwards. Slower but non-buggy.
claytas
12/09/2006 12:24am
Maybe too late, I only now stumbled on your site.

I would say the bug is that it didn't just say 'error'. Either alias the the expression, or put the aggregate in the group by. I am not so familiar with MySQL, mainly other SQLs.

select ParentPost, MAX(Date) as MAXDATE
from forum_post
where forumid=2
group by ParentPost
order by MAXDATE desc

select ParentPost, MAX(Date)
from forum_post
where forumid=2
group by ParentPost
order by Max(Date) desc
Reply