Hakan Axheim

Hakan Axheim

  • NA
  • 201
  • 32.6k

Need help with an SQL query in SQLserver

Dec 10 2018 7:41 AM
Hi,
 
I want to make a SQL question that selects the row with the highest incrementid. The current sql query is made with a subquery. I don't want any subquerys regarding to performance.
 
Data consists by. The last column value is increment id.
 
RID OwnerRID CreatedBy CreatedDate ValidFromDate ValidToDate IncrementId
BB7B6D1A-20FA-E811-A92B-1C4D701E2313 25C71200-60AE-443D-A0B7-424A7EDEA24C JMeterTest 2018-12-07 14:01:00 2017-12-01 12:00:00 2017-12-01 12:15:00 1118
689CB599-7DFC-E811-A92B-1C4D701E2313 57627ABA-51F3-4692-B3DE-0BBDD196C828 JMeterTest 2018-12-10 14:15:00 2017-12-01 12:00:00 2017-12-01 12:15:00 1241
699CB599-7DFC-E811-A92B-1C4D701E2313 57627ABA-51F3-4692-B3DE-0BBDD196C828 JMeterTest 2018-12-10 14:15:00 2017-12-01 12:00:00 2017-12-01 12:15:00 1242
 
I have tried to make an SQL query but it does not work:
 
SELECT PN.RID
FROM part.Participation PN
LEFT JOIN part.Participation PN1 ON (PN.OwnerRID = PN1.Ownerrid AND PN1.IncrementId > PN.IncrementId)
INNER JOIN @PARTICIPATION PARAM_PN ON (PARAM_PN.RID = PN.OwnerRID);
 
Can someone give me a tip! 

Answers (7)