469,087 Members | 1,277 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,087 developers. It's quick & easy.

GROUP BY and ORDER BY

Here's another one; thanks so much to everyone who helped with my last
problem. I can't upgrade mySQL but I figured out a way around it from your
examples.

SELECT `subject` , max( `datetime` )
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY `datetime` DESC LIMIT 0 , 30

The thing is...it doesn't order by `datetime`...it seems to be in a random
order. I've tried ORDER BY max(`datetime`) but that gives me an error that
says "#1111 - Invalid use of group function"

I could just sort it in PHP, but is there a better way?

Thanks
Jul 20 '05 #1
2 5209
"Experienced but Undocumented" <e0*@removethis.toao.net> wrote in message
Here's another one; thanks so much to everyone who helped with my last
problem. I can't upgrade mySQL but I figured out a way around it from your examples.

SELECT `subject` , max( `datetime` )
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY `datetime` DESC LIMIT 0 , 30

The thing is...it doesn't order by `datetime`...it seems to be in a random
order. I've tried ORDER BY max(`datetime`) but that gives me an error that says "#1111 - Invalid use of group function"

I could just sort it in PHP, but is there a better way?


Use column aliases.

SELECT `subject` , max( `datetime` ) as mdi
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY mdi DESC LIMIT 0 , 30

Incidentally, what is meaning of the apostrophe `
Jul 20 '05 #2

"Siemel Naran" <Si*********@REMOVE.att.net> wrote
Use column aliases.

SELECT `subject` , max( `datetime` ) as mdi


Perfect! Thanks so much for your help!
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Randell D. | last post: by
1 post views Thread by Rick | last post: by
5 posts views Thread by Mike Nolan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.