[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-07-14
4
Medium Priority
?
431 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

656 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