With this query I want to display only the most recent entry that have a similar PersonPosting and PostDate, in order to display the ID that is the most recent entry.
Table:
Post_ID | PersonPosting | PostDate | StartTime
1 2 2019-09-24 12:30pm
2 2 2019-09-24 12:33pm
3 2 2019-09-25 12:30pm
4 2 2019-09-25 12:33pm
5 1 2019-09-26 2:30pm
6 1 2019-09-26 2:31pm
7 1 2019-09-26 2:32pm
8 1 2019-09-26 2:33pm
I've tried adjusting the subquery to return the StartTime instead
SELECT
etl.Post_ID, etl.PersonPosting, etl.PostDate, etl.StartTime,
(SELECT MAX (post.PostTime) from [log].[Posts] post2
WHERE post2.PostDate = etl.PostDate AND etl2.PersonPosting = etl.PersonPosting) as Post_ID
FROM log.Posts post
WHERE
group by PostDate, PersonPosting, Post_ID, StartTime
Order By
etl.PostDate DESC,
PersonPosting ASC;
Expected Result:
Post_ID | PersonPosting | PostDate | StartTime
2 2 2019-09-24 12:33pm
4 2 2019-09-25 12:33pm
8 1 2019-09-26 2:33pm
Error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.