Re: [SQL] joining one record according to max value

2011-01-12 Thread George Francis
thanks! I think this is the best answer I will get. On Wed, Jan 12, 2011 at 6:05 PM, Jasmin Dizdarevic < jasmin.dizdare...@gmail.com> wrote: > There is probably a more elegant way, but this could help you. > > select i.source_id, nm.name, i.mxscore from ( > select sl.source_id, max(score) mxsco

Re: [SQL] joining one record according to max value

2011-01-12 Thread Jasmin Dizdarevic
There is probably a more elegant way, but this could help you. select i.source_id, nm.name, i.mxscore from ( select sl.source_id, max(score) mxscore from source s inner join sourcelevel sl on s.source_id = sl.source_id inner join level l on sl.level_id = l.level_id group by 1 ) i inner join ( sel

Re: [SQL] joining one record according to max value

2011-01-12 Thread George Francis
Close! but I need the name of the LEVEL with highest score, and I dont think I can get it this way. Thanks for trying though! On Wed, Jan 12, 2011 at 5:49 PM, Jasmin Dizdarevic < jasmin.dizdare...@gmail.com> wrote: > It's currently late, so excuse me if I'm wrong. Is this, what you like to > hav

Re: [SQL] joining one record according to max value

2011-01-12 Thread Jasmin Dizdarevic
It's currently late, so excuse me if I'm wrong. Is this, what you like to have? select sl.source_id, max(score) from source s inner join sourcelevel sl on s.source_id = sl.source_id inner join level l on sl.level_id = l.level_id group by 1 This is the highest score per source_id. 2011/1/12 Geor

Re: [SQL] joining one record according to max value

2011-01-12 Thread George Francis
hmm, but if I try to constrain the inner query to the source_id of the outer query I get an error as follows: select source.source_id, score, name from source left join ( select * from sourcelevel, level where sourcelevel.level_id = level.level_id and sourcelevel.source_id = source.source_id order

[SQL] joining one record according to max value

2011-01-12 Thread George Francis
The following sql is intended to produce a list of all unique SOURCEs, along with the corresponding LEVEL.NAME for LEVEL with highest SCORE value via SOURCELEVEL. I'd like to know why it doesn't return a SCORE value for SOURCE with id 3, despite there being a SOURCELEVEL entry for it. Many thank