Solved

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

Posted on 2009-07-14
4
417 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 50 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 50 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

691 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