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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:47:41+00:00 2026-05-26T15:47:41+00:00

I’m trying to run a query on a table that we keep for transactions

  • 0

I’m trying to run a query on a table that we keep for transactions regarding aspects of records of our database. To be more specific, when we “expire” an “asset” (as we call it), we change it’s state to expired in the main table, and then record the record of when it was expired in another (this was not my design).

The problem is, sometimes the end user gets impatient with the front-end and we end up with multiple expired transactions for a specific record from the other table.

The table in question is as follows:

+---------------+-----------------------------+------+-----+-------------------+-------+
| Field         | Type                        | Null | Key | Default           | Extra |
+---------------+-----------------------------+------+-----+-------------------+-------+
| m_id          | int(11)                     | NO   | PRI | 0                 |       | 
| a_ordinal     | int(11)                     | NO   | PRI | 0                 |       | 
| date_expired  | datetime                    | NO   | PRI |                   |       | 
| expire_state  | enum('EXPIRED','UNEXPIRED') | YES  |     | NULL              |       | 
| note          | text                        | YES  |     | NULL              |       | 
| created_by    | varchar(40)                 | YES  |     | NULL              |       | 
| creation_date | datetime                    | NO   |     |                   |       | 
| updated_by    | varchar(40)                 | NO   |     |                   |       | 
| last_update   | timestamp                   | NO   |     | CURRENT_TIMESTAMP |       | 
+---------------+-----------------------------+------+-----+-------------------+-------+

From what I can ascertain, m_id, a_ordinal and date_expired form a composite key.

What I need is a query to the table to display the most recent transaction for each expired record (m_id, a_ordinal, expired_date). Currently it’s displaying 809 records, but that’s because we could have multiple instances of when the record was expired:

|      2223 |      20 | 2011-05-02 12:15:43 | EXPIRED      | 165 Plays. Program quality is poor. 
|      2223 |      20 | 2011-05-02 12:16:05 | EXPIRED      | 165 Plays. Program quality is poor.

I know it involves a sub-query with a join, (or perhaps not?) but it’s been 5 years since I’ve worked with MySQL, and I’m very rusty. Any help would be 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-26T15:47:42+00:00Added an answer on May 26, 2026 at 3:47 pm
    SELECT t.m_id, t.a_ordinal, t.date_expired, t.note
    FROM expiry_table_name t
    INNER JOIN  (
        SELECT m_id, a_ordinal, MAX(date_expired) AS date_expired
        FROM expiry_table_name
        GROUP BY m_id, a_ordinal
        ) g
    ON g.m_id = t.m_id
    AND g.a_ordinal = t.a_ordinal
    AND g.date_expired = t.date_expired
    

    n.b. If you have duplicate date_expired values (for a specific m_id, a_ordinal combination) you’ll need to do something more sophisticated.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.