==========================================================================================================================A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

sunder.mekala (2/20/2013)if i go woth your suggestion then i need to group it by the other non aggregated columns, if i group it my results will go wrong, so i am thinking to use min(column1) over (order by column1) .

Any suggestion is appreciated.

Thanks,Sam.

Looks like you need to put your minimum part as a sub query if other columns are involved that you can't group by.

if i go woth your suggestion then i need to group it by the other non aggregated columns, if i group it my results will go wrong, so i am thinking to use min(column1) over (order by column1) .

What other columns, there were non specified? Why will the results be wrong, in what way?

Sorry but without a little more information (i.e. DDL's and sample data would be perfect) we just can't see based upon this sorry..

Cheers

Andy

==========================================================================================================================A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

Looks like you need to put your minimum part as a sub query if other columns are involved that you can't group by.

If this is what the OP is looking for then maybe..?:

(Just a guess )

SELECT <SomeCols>

FROMSometable AS ST

INNER JOIN -- If no NULLs are needed from this sub query(SELECT<SomeID>,MIN(ST.BG_DTTM) 'Minim'FROMtablename STGROUP BY,<SomeID>

) AS SubQ

ON ST.<SomeID> = SubQ.<SomeID>

Cheers

Andy

==========================================================================================================================A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

Basically i have the above query which gives me PKG_NME which has latest time associated with it.

my requirement is among the PKG_NME from the above dataset which are assocated with BG_DTTM, END_DTTM, i have to find the difference of time between min(BG_DTTM) and max(END_DTTM) from the above dataset ONLY, here the reason why i am saying only is PKG_NME will have different BG_DTTM and END_DTTM as it is a logging table, but here i have find the difference between the LATEST MIN(BG_DTTM)) and max(END_DTTM).