SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Finding Earliest Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/26/2013 :  07:39:33  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 11/26/2013 :  07:42:10  Show Profile  Reply with Quote

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



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 11/26/2013 07:42:48
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000