Mega Search
23.2 Million


Sign Up

Make a donation  
Query Issue with Date  
News Group: microsoft.public.sqlserver.server

Hi,

I have the following output in a table:

UID	FID	nDate
-----------------------------------
178	100	2013-06-03 16:12:23.000
178	99	2013-05-30 07:30:41.000
178	99	2013-05-30 07:26:59.000
178	99	2013-05-30 07:24:14.000
178	99	2013-05-29 06:58:13.000
178	99	2013-05-29 06:51:59.000
178	99	2013-05-28 20:02:10.000

I just want to retrieve UID, FID and Date column based on latest date entry so the result should look like this:

UID	FID	nDate
-----------------------------------
178	100	2013-06-03 16:12:23.000
178	99	2013-05-30 07:30:41.000

Any help would be great.


Vote for best question.
Score: 0  # Vote:  0
Date Posted: 7-Jun-2013, at 6:45 AM EST
From: m
 
Re: Query Issue with Date  
News Group: microsoft.public.sqlserver.server
sumikumar@gmail.com wrote:

> Hi,
>
> I have the following output in a table:
>
> UID     FID     nDate
> -----------------------------------
> 178     100     2013-06-03 16:12:23.000
> 178     99      2013-05-30 07:30:41.000
> 178     99      2013-05-30 07:26:59.000
> 178     99      2013-05-30 07:24:14.000
> 178     99      2013-05-29 06:58:13.000
> 178     99      2013-05-29 06:51:59.000
> 178     99      2013-05-28 20:02:10.000
>
> I just want to retrieve UID, FID and Date column based on latest date entry so the result should look like this:
>
> UID     FID     nDate
> -----------------------------------
> 178     100     2013-06-03 16:12:23.000
> 178     99      2013-05-30 07:30:41.000
>
> Any help would be great.

Pretty basic...

SELECT UID, FID, MAX(nDate)
FROM my_table
GROUP BY UID, FID

--
Gert-Jan



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Jun-2013, at 9:57 PM EST
From: Gert-Jan Strik