You are here: MySQL GROUP BY ignoring ORDER BY « PHP SQL « IT news, forums, messages
MySQL GROUP BY ignoring ORDER BY

Posted by Alexander on 07/14/07 13:08

Hi,

I am having two tables (table1, the primary table and table2 which holds
data referring to table1) which I am trying to combine with a LEFT JOIN.

Now I'd like to retrieve all values from table1 along with the number of
their entries in table2, sorted descending by the table2's timestamp
however to get the "last".

SELECT table1.*, table2.time, COUNT(table2.t1ref)
FROM table1
LEFT JOIN table2 ON table2.t1ref=table1.id
GROUP BY table1.id
ORDER BY table2.time DESC

The problem now is that it seems using a GROUP BY ignores the indicated
ORDER BY statement as I am not getting the last entry's date.

Does anybody have an idea on how to solve this?

Thanks,
Alexander

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация