Solved

SQL Select unique records with max date  for Oracle10g

Posted on 2011-09-14
3
345 Views
Last Modified: 2012-05-12
Experts,

I am stumped on a SQL select query against an Oracle 10g database.
I need to select every unique combination of CUST and ITEM. Where there is more than one, I need the most recent date returned. I put an asterix on the desired results. The date is a proper system date and sorts properly in a query.


Cust      Item            Date (YY-MM-DD)
A      COOKIE                          11-09-15  *
A      COOKIE                          10-06-24
A      COOKIE                           98-07-21
A      PIZZA            08-02-15  *
A      DONUT            10-02-21  *
B      PIZZA            11-05-03  *
B      PIZZA            08-12-31
B      PIZZA            06-06-07      
B      DONUT            10-11-05  *
C      DONUT            99-02-03  *
C      PIZZA            03-04-18  *
0
Comment
Question by:JDCam
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 36538746
try this:

select cust, item, date_col from
(
select cust, item, date_col, row_number() over(partition by cust, item order by date_col desc) myrownum from table_name
)
where myrownum=1
0
 

Author Closing Comment

by:JDCam
ID: 36538816
Works perfect ... Thanks !!
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36538824
Glad to help.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

813 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

9 Experts available now in Live!

Get 1:1 Help Now