Solved

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

Posted on 2009-07-14
4
394 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
  • 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 31

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now