Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Select unique records with max date  for Oracle10g

Posted on 2011-09-14
3
Medium Priority
?
377 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 2000 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
 
LVL 1

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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.

596 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