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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:20:51+00:00 2026-06-08T00:20:51+00:00

I have the following data. ——————————————————————————– id | value_name | last_modified | system_id |

  • 0

I have the following data.

--------------------------------------------------------------------------------
id             | value_name    | last_modified | system_id     | value_data    |
--------------------------------------------------------------------------------
1              | name1         | 2012-06-04    | 1             | aaa           |
2              | name1         | 2012-02-04    | 1             | bbb           |
3              | name1         | 2012-04-25    | 1             | ccc           |
4              | name2         | 2012-07-04    | 1             | ddd           |
5              | name2         | 2012-06-14    | 1             | eee           |
6              | name3         | 2011-09-05    | 1             | qqq           |
--------------------------------------------------------------------------------

Now I need to get only most recently modified values.

update

For the table above I want to get the following result

--------------------------------------------------------------------------------
id             | value_name    | last_modified | system_id     | value_data    |
--------------------------------------------------------------------------------
1              | name1         | 2012-06-04    | 1             | aaa           |
4              | name2         | 2012-07-04    | 1             | ddd           |
6              | name3         | 2011-09-05    | 1             | qqq           |
--------------------------------------------------------------------------------

I searched a lot here and in google as well, but the solutions I was able to find doesn’t actually work. For example one of the proposed solutions is usign join.

SELECT
    v.[id],
    v.[system_id],
    v.[value_name],
    v.[value_data]
FROM
    [values] v INNER JOIN
    (
        SELECT
            v.[id],      
            MAX(v.[last_modified]) AS last_modified
        FROM
            [values] v
        WHERE
            v.[system_id] = 1
        GROUP BY
            v.[id]
    ) s 
ON
    v.[id] = s.[id]

But sub-query is grouped by id (which is unique), so it will not calculate max last modification dates.
I’m using SQLite and simple query like that works for me

SELECT
    v.[id],
    v.[system_id],
    v.[value_name],
    v.[value_data],
    MAX(v.[last_modified]) AS last_modified
FROM
    [values] v
WHERE
    v.[system_id] = 1
GROUP BY
    v.[value_name]

But I remember from Oracle that you can’t select fields that are not listed in either aggregate functions or in group by statement, so I’m not sure this is guaranteed to give me expected result. Any suggestions how to solve that?

Thanks in advance.

  • 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-08T00:20:53+00:00Added an answer on June 8, 2026 at 12:20 am

    If last_modified is unique per value_name, you can use this:

    SELECT
        v.[id],
        v.[system_id],
        v.[value_name]
    FROM
        [values] v INNER JOIN
        (
            SELECT
                v.[value_name],      
                MAX(v.[last_modified]) AS last_modified
            FROM
                [values] v
            WHERE
                v.[system_id] = 1
            GROUP BY
                v.[value_name]
        ) s 
    ON
        v.[value_name] = s.[value_name]
    AND
        v.[last_modified] = s.[last_modified]
    

    If not, you will need to extract last id for last_modified grouped by value_name:

    SELECT
        v.[id],
        v.[system_id],
        v.[value_name]
    FROM
        [values] v INNER JOIN
        (
            SELECT max(id) ID
              FROM [values] v_max
             INNER JOIN
             (
                 SELECT
                     [value_name],      
                     MAX([last_modified]) AS last_modified
                 FROM
                     [values]
                 WHERE
                     [system_id] = 1
                 GROUP BY
                     [value_name]
             ) s 
              ON
                  v_max.[value_name] = s.[value_name]
              AND
                  v_max.[last_modified] = s.[last_modified]
             GROUP BY s.value_name, s.last_modified
       ) maxID
       ON v.ID = maxID.ID
    

    Disclaimer: not tested.

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

Sidebar

Related Questions

I have the following data in a SQL Server 2000 table: Dates ----------------------- 2012-05-04
I have following data Table1 id col1 col2 col3 ---------------------------------- 1 abc 01/01/2012 -
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14
I have following data structure (simplified): A giant list of the class TestClass public
I have following data to save in database using php my data is :
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have following data in a file called binFile 78 1 79 4 80
I have following data: a=[3 1 6]'; b=[2 5 2]'; c={'ab' 'bc' 'cd'}'; I
I have the following data inside an NSData object: <00000000 6f2d840e 31504159 2e535953 2e444446

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.