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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:17:30+00:00 2026-06-11T20:17:30+00:00

id tmpname date_used tkt_nr —|———|——————|——–| 1 | template| 04/03/2009 16:10 | 00011 | 2

  • 0
id   tmpname      date_used        tkt_nr
---|---------|------------------|--------|
1  | template| 04/03/2009 16:10 | 00011  |
2  | templat1| 04/03/2009 16:11 | 00011  |
5  | templat2| 04/03/2009 16:12 | 00011  |
3  | diffname| 03/03/2009 15:11 | 00022  |
4  | diffname| 03/03/2009 16:12 | 00022  |
6  | another | 03/03/2009 16:13 | NULL   |
7  | somethin| 24/12/2008 11:12 | 00023  |
8  | name    | 01/01/2009 12:12 | 00026  |

I would like to have the result:

id   tmpname      date_used        tkt_nr
---|---------|------------------|--------|
5  | templat2| 04/03/2009 16:12 | 00011  |
4  | diffname| 03/03/2009 16:12 | 00022  |
7  | somethin| 24/12/2008 11:12 | 00023  |
8  | name    | 01/01/2009 12:12 | 00026  |

So what I’m looking for is to have distinct tkt_nr values excluding NULL, based on the max value of datetime.

I have tried several options but always failed

SELECT *
FROM  templateFeedback a 
JOIN (
      SELECT ticket_number, MAX(date_used) date_used
      FROM   templateFeedback
      GROUP BY ticket_number
     ) b 
ON a.ticket_number = b.ticket_number AND a.date_used = b.date_used

I would appreciate any help. Unfortunately I need the code to be compatible with SQL Server.

  • 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-06-11T20:17:31+00:00Added an answer on June 11, 2026 at 8:17 pm

    I’ve stopped doing things this way since I discovered windowing functions. Too often, there are two records with the same timestamp and I get two records in the resultset. Here’s the code for tSQL. Similar for Oracle. I don’t think mySQL supports this yet.

    Select id, tmpname, date_used, tkt_nbr
    From 
    (
        Select id, tmpname, date_used, tkt_nbr,
            rownum = Row_Number() Over (Partition by tkt_nbr Order by date_used desc)
    ) x
    Where row_num=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running WAMP server. On file upload using PHP I see $_FILES[tmp_name] =>
fclose() is causing a segfault. I have : char buffer[L_tmpnam]; char *pipeName = tmpnam(buffer);
I have this script <?php if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = dirname(__FILE__)
I am import from a CSV to Mysql, every works fines the only problem
I'm programming an API of sorts on a PHP website I built with the
I have a website on free hosting - 000webhost.com and it allows you to
I have some problems with a PHP script that calls a Bash script.... in
I have a wordpress theme with an options page. I have included a basic
I want a function that replace each li with an image. This is my
I get this warning saying that tmpnam is dangerous, but I would prefer to

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.