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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:38:14+00:00 2026-06-17T23:38:14+00:00

I have a few simliar tables. I need to select them through * .

  • 0

I have a few simliar tables. I need to select them through *.
I would like to get a list of the rows where revnr is the highest one within each docid.

My problem here is that I don’t know how to get the local max(revnr) for each docid.

I am using MySQL but I’d prefer a general sql solution.

Thanks!

  • 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-17T23:38:16+00:00Added an answer on June 17, 2026 at 11:38 pm

    You can get the latest value of revnr for each docID in a subquery then the result of that will then join to the table itself.

    SELECT  a.*
    FROM    tableName a
            INNER JOIN
            (
                SELECT  docID, MAX(revnr) max_val
                FROM    tableName
                GROUP   BY docID
            ) b ON  a.docID = b.docID AND
                    a.revnr = b.max_val
    

    for better performance, add an INDEX on both columns: docID and revnr

    ALTER TABLE tableName ADD INDEX (docID, revnr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have large MySQL tables with hundreds of thousands of rows. I need to
I have a situation where I need to generate a few similar anonymous delegates.
I have need to provide a way for users to edit tables in ASP.Net.
I need to left join a few tables in a query where the column
I have a SSRS local report and I need to display a list of
I have quite a few situations where I have database structures similar to: TABLE
There have been a few similar questions with solutions, but none answered my question,
I've seen a few similar posts and have tried out the answers given, but
Although I have read a few previously answered questions regarding a similar issue, I
I made a similar question a few days ago, but now I have new

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.