Avatar of shpresa
shpresa
Flag for United States of America asked on

Select statement Query SQL

Hi Experts,
I need to create this report in sql by selecting the last record for each referralID. As you see below in the table i have the same referralID many times and i need to select 1 record per each referralID. That would be the last one entered, or the one with highest number of "StatusUpdateID". Suggestions?

Here is how the table looks like.
StatusUpdateID          ReferralID         Q1         Q2             Q3
1                                    685                      1           1                 2
2                                    685                      1            1                 1
3                                    685                      1           0                 0
4                                    688                       0           0                 1
5                                    688                      1            1                 1
6                                    689                      1              1               1
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes