• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 58
  • Last Modified:

get the third record from the suquery

I have the correlated subquery in the select statement and i need to get the third record. Right now I am getting it based on the unit number but it is wrong , I Need to get it based on the startDate

IsNull( (SELECT MAX(SU2.sessionstart) 
 FROM SessionUnit SU2 WITH (NOLOCK) WHERE SU2.sessionKey = SU.sessionkey AND [b]SU2.unitOrder = 3 [/b]) , NULL ) 
 AS purchaseenddate,

Open in new window

0
erikTsomik
Asked:
erikTsomik
1 Solution
 
Russ SuterCommented:
Use a subquery

SELECT TOP 1
  [TopOrders].[OrderDate]
FROM
(
SELECT TOP 3
  [OrderDate]
FROM
  [Orders]
ORDER BY
  [OrderDate] DESC
) as [TopOrders]
ORDER BY
  [TopOrders].[OrderDate] ASC

Open in new window

0
 
Anthony PerkinsCommented:
Any chance you can post the complete query?
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
erikTsomik, the full query can help us to give you a solution for your question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now