Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Help on retreiving Single record 1

Status
Not open for further replies.

AlStl

MIS
Oct 2, 2006
83
US
Guys,

Help needed in developing SQL. Following is the data set:

Name project# Event# Address

XXXX 321 EVT1 233 Le
XXXX 321 EVT2 244 Cali
YYYY 3dcc EVT1 555 Chicago
XXXX 321 EVT3 NY
PPPP 7777P EVT1 CO
LLLLL 8888X EVT1 LA
LLLLL 8888X EVT2 PA
CCCC 9999X EVT1 MI

Primary is key made up of: Name, Project#, and Event#

I would like to retrieve a single record (per primary key) based on highest Event# instance. For ex:

Oracle query executed against above records set should return (order by name):

Name project# Event# Address

CCCC 9999X EVT1 MI
LLLLL 8888X EVT2 PA
PPPP 7777P EVT1 CO
XXXX 321 EVT3 NY
YYYY 3dcc EVT1 555


Thanks,

Al
 
Try something like
Code:
SELECT * 
  FROM my_table
 WHERE (Name,project,Event) IN (SELECT name,project,max(event)
                                  FROM my_table
                                 GROUP BY name,project)
 ORDER BY name;
 
Carp,

I see your logic and it makes sense. I will give it shot and let you know.


I appreciate it.

Thx.

Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top