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

2011-01-12 Thread George Francis
urce_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 ( > select name, max(score) as mxs from level > group by 1 > ) nm on i.mxscore = nm.mxs > >

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

2011-01-12 Thread George Francis
s, 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 George Franc

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

2011-01-12 Thread George Francis
nnot be referenced from this part of the query. Character: 601 On Wed, Jan 12, 2011 at 5:35 PM, Jasmin Dizdarevic < jasmin.dizdare...@gmail.com> wrote: > Because of the "score desc limit 1". The subselect returns only the higest > score and this is level 2. > > 2011/1

[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