Home > Archive > MS SQL Server MSEQ > March 2005 > Re: query assistance -return most recent date









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: query assistance -return most recent date
resprog2

2005-03-30, 7:04 pm


Hugo Kornelis wrote:
> *On Fri, 11 Feb 2005 08:35:07 -0800, Rich_A2B wrote:
>
> field,
> but both
> three
> recent
>
> Hi Rich_A2B,
>
> I guess I should have seen that one coming :-)
>
> SELECT a.pkg_num, a.del_date_time, a.del_recip_name
> FROM MyTable AS a
> WHERE NOT EXISTS (SELECT *
> FROM MyTable AS b
> WHERE b.pkg_num = a.pkg_num
> AND b.del_date_time > a.del_date_tim)
>
> or
>
> SELECT a.pkg_num, a.del_date_time, a.del_recip_name
> FROM MyTable AS a
> INNER JOIN (SELECT pkg_num, MAX(del_date_time) AS
> max_del_date_time
> FROM MyTable
> GROUP BY pkg_num) AS b
> ON a.pkg_num = b.pkg_num
> AND a.del_date_time = b.max_del_date_time
>
> or
>
> SELECT a.pkg_num, a.del_date_time, a.del_recip_name
> FROM MyTable AS a
> WHERE a.del_date_time = (SELECT MAX(del_date_time)
> FROM MyTable AS b
> WHERE b.pkg_num = a.pkg_num)
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address) *




--
resprog2
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1415285.html

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com