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

  • Home
  • SEARCH
  • 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 6113107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:16+00:00 2026-05-23T14:49:16+00:00

I am really struggling with the issue below and need some help…I have found

  • 0

I am really struggling with the issue below and need some help…I have found few responses but not leading me the right way…

Table1

 sub-id  ref-id    Name
    1       1         Project 1
    2       1         Project 2  
    3       2         Project 3
    4       2         Project 4-

Table2

 sub-id  ref-id    log_stamp      Recepient      log_type
    ----------------------------------------------------
    1     1       06/06/2011     person A       1
    1     1       06/14/2011     person B       2
    1     1       06/16/2011     person C       2
    1     1       06/17/2011     person D       3
    2     1       06/18/2011     person E       2
    2     1       06/19/2011     person F       2

    3     2       06/20/2011     person G       1
    4     2       06/23/2011     person H       3

Result

Name        ref-id    start_date    Recepient     latest_comment Recepient completion_date  Receipient
Project1    1         06/06/2011    person A      06/19/2011     person F      06/17/2011   person D
Project3    2         06/20/2011    person G      NULL           NULL          06/23/2011   person H

log_type of 1 stands for start_date
log_type of 2 stands for
latest_comment log_type of 3 stands
for completion_date we need to
max_date in the date column to be
displayed for each log_type. The Name
of the project is just the name of the
top-most name in the same group of
ref-id have tried this for now

  • 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-23T14:49:17+00:00Added an answer on May 23, 2026 at 2:49 pm

    For SQL Server 2005+:

    WITH cteMaxDates AS (
        SELECT sub_id, ref_id, log_type, MAX(log_stamp) AS MaxDate
            FROM Table2
            GROUP BY sub_id, ref_id, log_type
    ),
    cteRecipient AS (
        SELECT md.sub_id, md.ref_id, md.log_type, md.MaxDate, t2.Recipient
            FROM cteMaxDates md
                INNER JOIN Table2 t2
                    ON md.sub_id = t2.sub_id 
                        AND md.ref_id = t2.ref_id
                        AND md.log_type = t2.log_type
                        AND md.MaxDate = t2.log_stamp
    )
    SELECT t1.Name, t1.ref_id, 
           start.MaxDate AS start_date,
           start.Recipient AS start_recipient,
           comment.MaxDate AS latest_comment,
           comment.Recipient AS comment_recipient,
           complete.MaxDate AS completion_date,
           complete.Recipient AS completion_recipient
        FROM Table1 t1
            LEFT JOIN cteRecipient start
                ON t1.sub_id = start.sub_id
                    AND t1.ref_id = start.ref_id
                    AND start.log_type = 1
            LEFT JOIN cteRecipient comment
                ON t1.sub_id = comment.sub_id
                    AND t1.ref_id = comment.ref_id
                    AND comment.log_type = 2
            LEFT JOIN cteRecipient complete
                ON t1.sub_id = complete.sub_id
                    AND t1.ref_id = complete.ref_id
                    AND complete.log_type = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this issue for some days now and I really
I am currently struggling with a really really strange issue. I have a telephone
So I have been really struggling to grasp the concept, but I am making
I have been struggling with this issue for about 10 hours straight. I really
For some reason I'm really struggling with this. I'm new to wpf and I
I am trying to read the following xml stream but am really struggling. <channelSnapshot
I've been struggling with this issue for a while now. Maybe you can help.
I have been struggling with this problem for a few days now and I
I am really struggling to understand tail recursion in Erlang. I have the following
really struggling to resolve this issue. using nhibernate Im trying to join two different

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.