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 6988331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:03:59+00:00 2026-05-27T19:03:59+00:00

I created a cursor from the one that was described on this post: SQL

  • 0

I created a cursor from the one that was described on this post: SQL – Call Stored Procedure for each record

But what I really want is a set based solution. I have two tables, Tickets and WorkLogs.
Each Ticket can have multiple worklogs, I just want the most recent for each ticket.

 SELECT WorkLog.WorkLogDate, WorkLog.TextEntry, Ticket.ID,
             Ticket.Summary, Ticket.Requester, Ticket.Status, Ticket.Priority, 
             Ticket.AssignedTo, Ticket.DateResolved, Ticket.TimeSpent
 FROM Ticket INNER JOIN WorkLog ON Ticket.ID = WorkLog.TicketIDRef

If I could somehow SELECT TOP (1) _WorkLog_ FROM WorkLog ORDER BY WorkLogID DESC for each Ticket.ID in Tickets I would have the set I’m looking for. I saw some similar solutions using CROSS APPLY but I’m not sure what function I would need to apply.

Any help getting my brain out of OO gear is greatly appreciated.

  • 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-27T19:04:00+00:00Added an answer on May 27, 2026 at 7:04 pm

    There are several ways of doing it.

    1) NOT EXISTS

    SELECT WorkLog.WorkLogDate, WorkLog.TextEntry, Ticket.ID,
                 Ticket.Summary, Ticket.Requester, Ticket.Status, Ticket.Priority, 
                 Ticket.AssignedTo, Ticket.DateResolved, Ticket.TimeSpent
     FROM Ticket INNER JOIN WorkLog ON Ticket.ID = WorkLog.TicketIDRef
    WHERE not exists (SELECT 1 FROM WorkLog w2 WHERE w2.TicketIDRef = Ticket.ID AND w2.WorkLogDate > WorkLog.WorkLogDate)
    

    2) Sub select

      SELECT 
           (
            SELECT TOP 1 
              WorkLog.TextEntry 
            FROM 
              WorkLog 
            WHERE 
              Ticket.ID = WorkLog.TicketIDRef
            ORDER BY
              WorkLog.WorkLogDate DESC
           ) as TextEntry, 
           Ticket.ID,
           Ticket.Summary, Ticket.Requester, Ticket.Status, Ticket.Priority, 
           Ticket.AssignedTo, Ticket.DateResolved, Ticket.TimeSpent
     FROM Ticket
    

    3) Joins

    SELECT WorkLog.WorkLogDate, WorkLog.TextEntry, Ticket.ID,
                 Ticket.Summary, Ticket.Requester, Ticket.Status, Ticket.Priority, 
                 Ticket.AssignedTo, Ticket.DateResolved, Ticket.TimeSpent
     FROM Ticket 
            INNER JOIN WorkLog ON Ticket.ID = WorkLog.TicketIDRef
            INNER JOIN (
                         SELECT 
                           max(WorkLogDate), 
                           TicketIDRef
                         FROM
                           WorkLog w2
                         GROUP BY
                           TicketIDRef
                        ) wMax ON
              WorkLog.WorkLogDate = wMax.WorkLogDate AND
              wMax.TicketIDRef = WorkLog.TicketIDRef
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a procedure(p1). This procedure opens a cursor(c1). And i call another
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I am trying to write a stored procedure that will allow me to write
I created stored proc so that user can select multiple comma separated values into
When I create areport in VS 2008 and try to use this stored procedure
In Sql server, i write a procedure and i use one tem table and
I am trying to take a stored procedure that copies parent/child/grandchild rows into the
i was just working with cursor in SQL 2008 but i face some problems.
Is it possible to create a cursor from an image and have it be
X has the method XCreatePixmapCursor to create a cursor from a pixmap with a

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.