How about this?
SELECT ParentID, MAX(ChildID) AS ChildID
FROM TableName
GROUP BY ParentID
Updated to edit missed requirement to return all rows:
Test Data
-- Populate Test Data
CREATE TABLE #table (
ParentID varchar(3) NOT NULL,
ChildID varchar(3) NOT NULL
)
INSERT INTO #table VALUES ('001','001')
INSERT INTO #table VALUES ('001','001')
INSERT INTO #table VALUES ('001','001')
INSERT INTO #table VALUES ('001','002')
INSERT INTO #table VALUES ('001','002')
INSERT INTO #table VALUES ('001','002')
INSERT INTO #table VALUES ('001','003')
INSERT INTO #table VALUES ('001','003')
INSERT INTO #table VALUES ('001','003')
INSERT INTO #table VALUES ('001','003')
INSERT INTO #table VALUES ('001','004')
INSERT INTO #table VALUES ('001','004')
INSERT INTO #table VALUES ('001','005')
INSERT INTO #table VALUES ('001','005')
INSERT INTO #table VALUES ('001','005')
INSERT INTO #table VALUES ('001','005')
Results
-- Return Results
DECLARE @ParentID varchar(8)
SET @ParentID = '001'
SELECT T1.ParentID, T1.ChildID
FROM #table T1
JOIN (
SELECT Q1.ParentID, MAX(Q1.ChildID) AS ChildID
FROM #table Q1
GROUP BY ParentID
) ParentChildMax ON ParentChildMax.ParentID = T1.ParentID AND ParentChildMax.ChildID = T1.ChildID
WHERE T1.ParentID = @ParentID
Note: The performance of this solution is identical to the accepted solution (according to SQL Server profiler) using the following statement in the WHERE clause. But I like my solution better as it seems cleaner to me and can be easily extended to include other ParentIDs is required. (For example, reporting purposes.)
(SELECT MAX(childId) FROM #table WHERE parentId = @ParentID)