Dnia wtorek, 5 lutego 2008, Gerry Snyder napisaƂ:
> P Kishor wrote:
> > sqlite> select t.* from test t join (select name, max(weight) as m
> > from test group by name) w on t.weight = w.m and t.name = w.name;
>
[...]
>
> select * from test join (select name as n, max(weight) as m from test
> group by name) where name = n and weight = m;

Thank You very much.
I know, that GROUP BY should have all SELECT fields, but thought, that he will 
choose row with MAX(), not the last row in dataset.

With the problem of "ties" I suppose, the easiest (but not SQL) way to make 
for() loop for each group (SELECT DISTINCT name), and do 
SELECT * FROM test WHERE name='{loop name}' ORDER BY weight DESC LIMIT 1

vip;
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to