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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:22+00:00 2026-05-29T08:05:22+00:00

Given following Table select rv, mv, datetime, rawv from mytable where datetime > ‘2012-01-30’;

  • 0

Given following Table

select rv, mv, datetime, rawv from mytable where datetime > '2012-01-30';
+------+------+---------------------+------+
| rv   | mv   | datetime            | rawv |
+------+------+---------------------+------+
|    5 |   81 | 2012-01-31 07:00:00 |    1 |
|    5 |   81 | 2012-01-31 07:01:00 |    2 |
|    5 |   82 | 2012-01-31 07:00:00 |    3 |
|    5 |   82 | 2012-01-31 07:01:00 |    4 |
|    5 |   83 | 2012-01-31 08:00:00 |    5 |
|    5 |   83 | 2012-01-31 08:01:00 |    6 |
+------+------+---------------------+------+

I’m looking for a SQL-statement which provides the records with the maximal datetime value for each rv, mv group. The result should look like:

+------+------+---------------------+------+
| rv   | mv   | max(datetime)       | rawv |
+------+------+---------------------+------+
|    5 |   81 | 2012-01-31 07:01:00 |    2 |
|    5 |   82 | 2012-01-31 07:01:00 |    4 |
|    5 |   83 | 2012-01-31 08:01:00 |    6 |
+------+------+---------------------+------+

Do you know such a statement?

What I’ve tried so far is following, but as you can see I’m getting wrong results:

select rv, mv, max(datetime), rawv from mytable
where mv in (81,82,83)
group by rv, mv;
+------+------+---------------------+------+
| rv   | mv   | max(datetime)       | rawv |
+------+------+---------------------+------+
|    5 |   81 | 2012-01-31 07:01:00 |    0 |
|    5 |   82 | 2012-01-31 07:01:00 |    0 |
|    5 |   83 | 2012-01-31 08:01:00 |    5 |
+------+------+---------------------+------+
3 rows in set (0.72 sec)

and

select rv, mv, datetime, rawv from mytable
where mp_nb in (81,82,83)
and datetime=(select max(datetime) from met_value);

+------+------+---------------------+------+
| rv   | mv   | datetime            | rawv |
+------+------+---------------------+------+
|    5 |   83 | 2012-01-31 08:01:00 |    6 |
+------+------+---------------------+------+
  • 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-29T08:05:23+00:00Added an answer on May 29, 2026 at 8:05 am

    Try this query –

    SELECT t1.rv, t1.mv, t1.datetime, t1.rawv FROM mytable t1
      JOIN (SELECT rv, mv, MAX(datetime) datetime FROM mytable GROUP BY rv, mv) t2
        ON t1.rv = t2.rv AND t1.mv = t2.mv AND t1.datetime = t2.datetime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following snippet A private static final String SQL = SELECT * FROM
The following two queries each give the same result: SELECT column FROM table GROUP
Given the following table in SQL Server 2005: ID Col1 Col2 Col3 -- ----
I have wrote the following SQL: SELECT s.*, (SELECT COUNT(*) FROM orders o WHERE
Problem Given the following two tables, I'd like to select all Ids for Posts
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Given the following html table and script shown below I am having a problem
Given the following: declare @a table ( pkid int, value int ) declare @b
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
Given the one-table design given below how would the following best be queried The

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.