?
Solved

Selecting rows from a atabel based on a a maximum value of a DATE column

Posted on 2009-07-14
4
Medium Priority
?
425 Views
Last Modified: 2013-12-07
Greetings,

I am having a problem doing something which in mind should really be simple but I can't get my head around it.

I have an unormalised  table with 10 columns, 3 of which will comprise the composite primary key.  Now for any two records where this primary key is identical, the other columns may vary, inlcuding a DATE.

What I would like as a result is a table of unique values as far as the primary key goes, and the other columns with values corresponding to the rows for that primary key where the DATE value is MAX.

I've tried coming up with a query which seemed right but I ended up getting a bloody cartesian product :(

This is my table:
ID
REGION
YEAR
CODE
SECTION
UNIT
LOCATION
MOVEMENT
VALUE
ACTION_DATE

Where ID, REGION and YEAR will comprise the primary key and ACTION_DATE is the DATE for which I want the maximum value of, along with the its respective values for the other columns.

Any help would be greatly appreciated!
0
Comment
Question by:FourHorsemen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 200 total points
ID: 24857768
select ID,
REGION,
YEAR,
CODE,
SECTION,
UNIT,
LOCATION,
MOVEMENT,
VALUE,
ACTION_DATE,
max(action_date) over ( partition by id, region,year order by id,region,year )
from your_table_name

but this will get all rows in the table with max action date.

can you provide some sample data and the output you need, so i can be precise with the query.
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 200 total points
ID: 24862713
See attached.
query.txt
0
 

Author Comment

by:FourHorsemen
ID: 24871554
Wow...both of those worked great!  Thanks!
0
 

Author Closing Comment

by:FourHorsemen
ID: 31603498
Thank you very much.  That worked perfectly!
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I showed you how to use console view (HERE (http://www.experts-exchange.com/articles/18379/Getting-Started-and-Using-the-Salesforce-com-Console.html)) -– but how do you set it up on the admin side of Salesforce? Note that you have to have Admin leve…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question