Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 5
    Works very well for smaller datasets. A downside is you'll have to have identical where clauses on the inner and outer query. Commented Sep 12, 2012 at 14:29
  • Since some of my dates were exactly the same (down to the fraction of a second) I had to add: row_number() over (order by txndate) to the inner and outer table and a few compound indices to make it run. Slick/simple solution. BTW, tested cross apply against subquery ... it's slightly faster. Commented Jan 5, 2015 at 4:39
  • this is very clean and does work well with small data sets; faster than the recursive CTE Commented Jun 23, 2016 at 15:41
  • this is nice solution as well (for small data sets), but you also have to be aware that it implies somedate column to be unique Commented Sep 29, 2016 at 8:04