Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Finding Earliest Date

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-11-26 : 07:39:33
HI all

I need some help

Aim- I want to find out the earliest [First_Post_Date] for any parentdid

My query (See below)
Produces the following results
SELECT
ParentID
,[First_Post_Date]
,[FDMSAccountNo]
FROM [FDMS].[dbo].[Dim_Outlet]
where ParentID = '878595212886'
Order by ParentID desc
Reslts -->
ParentID First_Post_Date FDMSAccountNo
878595212886 NULL 878595212886
878595212886 20080612 878595213884
878595212886 20090507 878595214882

Required results
ParentID First_Post_Date
878595212886 20080612

Looking forward to your help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-26 : 07:42:10
[code]
SELECT
t.ParentID
,[First_Post_Date]
,[FDMSAccountNo]
FROM [FDMS].[dbo].[Dim_Outlet] t
INNER JOIN (SELECT ParentID,MIN([First_Post_Date]) AS FirstDate
FROM [FDMS].[dbo].[Dim_Outlet]
GROUP BY ParentID
)t1
ON t1.ParentID = t.ParentID
AND t1.FirstDate = t.[First_Post_Date]
where t.ParentID = '878595212886'
Order by t.ParentID desc
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -