SQL - Select Top 1 multiple lines of the same id

I have the following query:

select * from [lead].[ContactFeedback] cf
where cf.LeadId in
(select LeadId from [lead].[LeadDetails]
where TeleportReference in (122096, 
122097, 
122098))
order by LeadId Desc

The results are something like this :

FeedbackDate            LeadId         
2015-01-23 16:25:13.547 95920
2015-01-23 16:25:38.960 95919
2015-01-23 16:25:19.393 95917
2015-01-23 16:25:32.837 95916
2015-01-23 16:25:59.840 95914
2015-01-23 16:26:08.840 95913
2015-01-23 16:15:01.933 95910
2015-01-23 16:22:04.820 95910
2015-01-23 16:24:40.477 95909
2015-01-23 16:24:03.523 95908
2015-01-23 16:16:44.290 95908
2015-01-23 16:17:16.047 95907
2015-01-23 16:25:11.783 95907

I want to list all top 1(most recent feedbackdate) for each LeadId. How can I achieve this in SQL Server?

Answers


select LeadId, Max(FeedbackDate) 
from [lead].[ContactFeedback] cf
where cf.LeadId in
    (select LeadId from [lead].[LeadDetails]
     where TeleportReference in (122096, 122097, 122098))
group by LeadId
order by LeadId Desc

Need Your Help

How to markup CakePHP Form to allow Text inputs inside a radio group

php forms cakephp radio

I am using CakePHP and the FormHelper to generate my form.

The * character in the Disallow statement of the Robots.txt File

search-engine web-crawler robots.txt search-engine-bots

How do different search bots interpret the * character in the disallow statement of the robots.txt file? Do all of them treat it as "none, one or more than one character" ?