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

The Archive Base Latest Questions

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

So the following query that I’m using produces 4 rows: SELECT `DMV`.`id` AS `dmvID`,

  • 0

So the following query that I’m using produces 4 rows:

SELECT 
  `DMV`.`id` AS `dmvID`,
  `D`.`id` AS `documentID`,
  `DMV`.`name` AS `documentName`,
  `U`.`username` AS `creatorUserName`,
  `D`.`folder_id` AS `folderID`,
  `D`.`created` AS `createDate`,
  `SL`.`name` AS `statusName`,
  `UM`.`username` AS `modifiedUserName`,
  `DMV`.`version_created` AS `modifiedDate`,
  `UO`.`username` AS `ownerUserName`,
  `DTL`.`name` AS `documentTypeName` 
FROM 
  `document_metadata_version` `DMV`
  LEFT JOIN `documents` `D` 
    ON `DMV`.`document_id` = `D`.`id`
  LEFT JOIN `users` `U` 
    ON `D`.`creator_id` = `U`.`id`
  LEFT JOIN `users` `UM` 
    ON `D`.`modified_user_id` = `UM`.`id`
  LEFT JOIN `users` `UO` 
    ON `D`.`owner_id` = `UO`.`id`
  LEFT JOIN `status_lookup` `SL` 
    ON `D`.`status_id` = `SL`.`id`
  LEFT JOIN `document_types_lookup` `DTL` 
    ON `DMV`.`document_type_id` = `DTL`.`id`
WHERE
    DMV.document_id = 543433
;

For the sake of brevity, I’ll omit all the irrelevant fields not related to the question at hand. The results of dmvID and documentTypeName (first and last columns) are:

+--------+------------------+
| dmvID  | documentTypeName |
+--------+------------------+
| 566053 | Default          |
| 566183 | Default          |
| 681391 | ASCO Documents   |
| 681411 | ASCO Documents   |
+--------+------------------+

I’m only interesting in the last row, so naturally, I’ll modify the SELECT statement to use MAX() on dmvID:

SELECT 
  MAX(`DMV`.`id`) AS `dmvID`,
# Rest of query unchanged

That returns:

+--------+------------------+
| dmvID  | documentTypeName |
+--------+------------------+
| 681411 | Default          |
+--------+------------------+

Note from above that 681411 is in fact the MAX(), but the associated documentTypeName is not the equivalent value for dmvID 681411, I would assume it’s matching it to dmvID 566053. How do I get it to return:

+--------+------------------+
| dmvID  | documentTypeName |
+--------+------------------+
| 681411 | ASCO Documents   |
+--------+------------------+
  • 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-07T02:05:28+00:00Added an answer on June 7, 2026 at 2:05 am

    If you only need the single row with the highest value in that column, use ORDER BY and LIMIT 1 (instead of an aggregating query using MAX()).

    ...
    WHERE
    DMV.document_id = 543433
    ORDER BY dmvID DESC
    LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query that returns 1738 rows: select a.street, b.id from TableA
I have a select query that currently produces the following results: Description Code Price
I have the following query that retrieve the number of users per country; SELECT
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have the following query That gets the city name, city id, the region
I have the following query that I'm executing using a Python script (by using
I have the following query that returns rows based on a comma seperated list
I have the following query that works under Hibernate but not under eclipse: select
I have the following query that retrieves what I need from the database: SELECT
I have the following query that has no errors: SELECT u.user_name, u.user_lastn, outer_s.movie_id, outer_s.times_rented

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.