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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:05:28+00:00 2026-06-07T12:05:28+00:00

table(ms_replies) |——————————————| | id | ticketID | replyStamp | |——————————————| | 1 | 7

  • 0
table(ms_replies)  
|------------------------------------------|
| id | ticketID |  replyStamp              |
|------------------------------------------|
| 1  |  7       | Tue 11 Oct 2011, 8:56am  |
| 2  |  7       | Wed 12 Oct 2011, 9:20am  |
| 3  |  8       | Wed 12 Oct 2011, 16:24pm |
| 4  |  7       | Thu 27 Oct 2011, 20:28pm |
| 5  |  8       | Tue 18 Oct 2011, 9:54am  |
|------------------------------------------|

The code I have thus far is:

SELECT 
    ticketID,
    MAX(replace(replace(replyStamp, 'pm',''), 'am','')) AS time
FROM 
    ms_replies 
WHERE 
    `ticketID` IN ($IDs)
GROUP BY 
    ticketID

But this doesn’t return the most recent entry.

Please note the replace in the query is necesary to remove the am | pm , this is not my doing, but I cannot chage it, unfortunatly.

  • 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-07T12:05:31+00:00Added an answer on June 7, 2026 at 12:05 pm

    You have to convert your strings into dates if you want to compare them as dates:

    SELECT ticketID,
             MAX(STR_TO_DATE(
               REPLACE(REPLACE(replyStamp, 'am', ''), 'pm', ''), 
               '%a %d %b %Y, %T')) AS max_time
        FROM ms_replies 
       WHERE ticketID IN (7, 8)
    GROUP BY ticketID;
    

    But it’s actually not required if the latest entry always have the max id (as in your sample); then you can just check MAX(id) instead, like in @ZaneBien answer – or here:

    SELECT m.ticketID, m.replyStamp
      FROM ms_replies AS m
     WHERE m.id = (
             SELECT MAX(id) FROM ms_replies 
             WHERE ticketID = m.ticketID
           );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table (in MS SQL 2005) with a selection of dates. I
I want to create a table in MS SQL Server 2005 to record details
In my MS SQL table, I read in an time_zone for a city from
How to update ms access table which contains single column with multiple rows. the
In one of the ms-access table I work with we have a text field
I'm working with the MS Surface table called Samsung SUR40 and use the language
I am trying to build a color table just like MS Office font color
I have a value in my MS SQL table column called XDATA like this:
I'm trying to update a record from an Ms-Access table with VB.NET and ASP.NET.
I try to get one data column from a MS-Access table and display it

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.