Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:01:00+00:00 2026-05-28T16:01:00+00:00

So, here it goes: I have a table that is returning timespans for a

  • 0

So, here it goes: I have a table that is returning timespans for a user ID. Unfortunately, it is returning duplicated timespans for some users (i.e. some users appear more than once in the results, because they have duplicated records in the query).

I want to select just the most recent timespan from the user results, for every user in the result set. I tried building a query that would SORT BY(), but that hasn’t proven fruitful. I think I am on the right track with that, but perhaps not.

Anyways, here is a sample summary of the output that I am trying to winnow out:

User        Activity 1                Activity1 ID  Activity 2               Activity2 ID
User 1      01-01-2009 - 12-31-2010   100.00        03-02-2009 - 05-05-2009  500.01
User 1      01-06-2009 - 12-31-2010   100.01        03-02-2009 - 05-05-2009  500.01
User 2      06-01-2009 - 12-31-2010   200.00        06-06-2010 - 03-03-2011  501.01

What I would like to do is return just the first ‘User 1’ category (or more specifically, the tuple with the longest timespan). I am using MS SQL Server (TSQL), and it doesn’t support Temporal data structures (yet), but should in 2012.

Any thoughts from the collective?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:01:01+00:00Added an answer on May 28, 2026 at 4:01 pm

    I believe you’re looking to “partition” your query.
    These should help:

    The OVER clause.

    The ROW_NUMBER function.

    Some interesting examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that I'm doing some special loading for. The user starts
Weird to describe but here goes. I have a table with several rows. One
Ok here goes: I have a table with id ( can be duplicate but
I have a table that contains some meta data in an XML field. For
Tables in HTML can have footers : <TABLE> <THEAD><TR><TD>Your header goes here</TD></TR></THEAD> <TFOOT><TR><TD>Your footer
I'm guessing this isn't possible, but here goes. I have two tables, and I'm
Ok here goes: I have a SELECT drop down option with US state names
This question might be kind of elementary, but here goes: I have a SQL
I'll try to explain my problem the best I can, here goes: I have
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.