Re: Query Question?
Posted in 1997
John Wells wrote:
>
> I am trying to select the most row from a group rows based on the date the
> row was inserted. I must get only the the most current row in each case.
> Here are some tries that did not work.
I am not sure exactly what you are trying to accomplish, but
the following has an error:
> select fld1, fld2, fld3, fld4, fld5, fld6, group
> from table1 t1
> wheret3=
(select max(fld3)
> table1 t2
> where t1.fld1 = t2.fld1
> and t1.fld2 = t2.fld2)
> and (fld4 is not null
> or fld5 is not null
> or fld6 is not null)
and I don't think you want the following group by:
> group by t1.fld1, t1.fld2, t1.fld3, fld4, fld5, fld6, group;
and the whole thing is probably more efficiently executed in
2 selects:
select fld1, fld2, max(fld3) fld3
from table
where
(fld4 is not null or fld5 is not null or fld6 is not null)
group by 1,2
into temp tmp_table with no log
select t1.*
from table t1, tmp_table t2
where t1.fld1=t2.fld1
and t2.fld2=t2.fld2
and t3.fld3=t3.fld3
Like I said, I don't know if this is what you want, but
maybe it'll give you more ideas, or maybe you can more
explicitly state what you're trying to do.
Douglas Wilson