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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:35:22+00:00 2026-05-13T13:35:22+00:00

I am trying to write a query that will return only the most recent

  • 0

I am trying to write a query that will return only the most recent results. The table I am pulling information from has no uniqiue columns, and contains information on rate changes so for any particular client there can be several rate changes – I only want the most recent rate change for each client.

The structure is:

mrmatter VARCHAR(14)
mrtk VARCHAR(14)
mreffdate DATETIME
mrtitle VARCHAR(100)
mrrate INT
mrdevper INT

Some sample data is:

mrmatter         mrtk      mreffdate                  mrtitle  mrrate   mrdevper
184-00111        0005      2001-03-19 00:00:00.000    !        250      NULL
184-00111        0259      2001-03-19 00:00:00.000    !        220      NULL
184-00111        9210      2001-03-19 00:00:00.000    !        220      NULL
184-00111        0005      2007-07-01 00:00:00.000    !        NULL     NULL

From the data above you can see there is two mrtk (0005), from these results it should only return three instead of the four rows.

The query isnt just on mrtk, instead of mrtk there could be a mrtitle in which case I would need to find the most recent date, when there is multiples.

I have tried the following query, it returns the results sorted in newest to oldest, but it returns four rows (two 0005) instead of only the three. I have tried different ways of doing the same query but it all returns the same results.

SELECT mrmatter,mrtk,mrrate,MAX(mreffdate) AS 'MostRecent'
FROM mexrate
WHERE mrmatter='184866-00111'
GROUP BY mrmatter,mrtk,mrrate

Any assistance that can be provided would be greatly appreciated.

UPDATE:
The mrrate column can contain nulls, and the nulls can be the most recent entry. What I am after is the most recent entry for the same mrmatter AND (mrtk OR mrtitle).

Some more sample data is:

mrmatter      mrtk               mrtk     mrrate   mreffdate
100626-01406    Senior Assoc    !   235.000 2006-01-25 00:00:00.000
100626-01406    Solicitor   !   235.000 2006-01-25 00:00:00.000
100626-01407    Associate            !  265.000 2006-01-30 00:00:00.000
100626-01407    Associate            !  276.000 2007-07-01 00:00:00.000
100626-01407    Partner          !  265.000 2006-01-30 00:00:00.000
100626-01407    Partner          !  276.000 2007-07-01 00:00:00.000
100626-01407    Senior Assoc    !   265.000 2006-01-30 00:00:00.000
100626-01407    Senior Assoc    !   276.000 2007-07-01 00:00:00.000

Matt

  • 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-13T13:35:22+00:00Added an answer on May 13, 2026 at 1:35 pm

    I was able to achieve what I was after by using this query:

    SELECT t1.mrmatter,t2.mrtk,t1.mrrate,t2.MostRecent
    FROM mexrate t1
    INNER JOIN
    (
        SELECT DISTINCT(mrtk),MAX(mreffdate) AS MostRecent
        FROM mexrate
        WHERE mrmatter='184866-00111'    
        GROUP BY mrtk
    ) t2 ON t1.mrtk=t2.mrtk AND t1.mreffdate=t2.MostRecent
    WHERE mrmatter='184866-00111' 
    

    Thanks everyone for your assistance with this problem, it is, as always, greatly appreciated.

    Matt

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

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Do the following: GtkWidget* entry = gtk_entry_new(); gtk_entry_set_editable(GTK_ENTRY(entry), TRUE); Welcome… May 14, 2026 at 7:16 pm
  • Editorial Team
    Editorial Team added an answer I don't know of another way besides a macro. But… May 14, 2026 at 7:16 pm
  • Editorial Team
    Editorial Team added an answer A few comments: *ptr = 10; // Doesn't need to… May 14, 2026 at 7:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.