Solved

SQL Select unique records with max date  for Oracle10g

Posted on 2011-09-14
3
368 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
[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
3 Comments
 
LVL 77

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 77

Expert Comment

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

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

717 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