RE: Ordering by unrelated column in a GROUP BY

2007-09-25 Thread Rob Wultsch
Peter, Thank you for your reply. MAX(t1.occurrence ) will pull the max of the occurrence column out of the group, but the other collumns (like data3 or id) would still be sorted by the GROUP BY. I will try your second solution, but the tables I am working are thousands of row and your solution lo

Re: Ordering by unrelated column in a GROUP BY

2007-09-25 Thread Peter Brawley
You might like to compare the performance of ... SELECT t1.data1, t1.data2, MAX(t1.occurrence) FROM t1 GROUP BY data1,data1 ORDER BY occurrence; with... SELECT t1.data1, t1.data2,t1.occurrence FROM t1 LEFT JOIN t1 AS t2 ON t1.data1=t2.data2 AND t1.data2=t2.data2 AND t1.occurrence < t2.occurre

Ordering by unrelated column in a GROUP BY

2007-09-25 Thread Rob Wultsch
Suppose I have a table: CREATE TABLE `t1` ( `id` int(11) NOT NULL auto_increment, `data1` varchar(50) , `data2` varchar(50) , `data3` varchar(50) , `occurance` datetime , PRIMARY KEY (`id`) ) And I want to pull the most recent entry of each set of unique combinations of `data1` and `d