sql - Getting the value of no grouping column -


i know basics in sql programming , know how apply tricks in sql server in order result set, don't know tricks in oracle.

i have these columns:

col1   col2   col3 

and wrote query

select      col1, max(col3) mx3       mytable  group      col1 

and need value of col2 in same row found max value of col3, know trick solve problem?

a couple of different ways this:

in both cases i'm treating initial query either common table expression or inline view , joining base table added column. trick here inner join eliminates records not in max query.

select a.*, mytable inner join (select col1 , max( col3 ) mx3 mytable group col1) b  on a.col1=b.col1 , b.mx3 = a.col3 

or

with cte (select col1 , max( col3 ) mx3 mytable group col1) select a.* mytable inner join cte  on a.col1 = b.col1 , a.col3= cte.mx3 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -