If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Query Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-06, 20:49
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
DB2 Query Question

Table Employee:

ID Name Project_Name Date
10 A AAA Jan 10, 2005
10 A AAA Nov 10, 2005
20 B BBB APR 10, 2005
20 B BBB DEC 10, 2005

I want to write a query where only one row is returned for each employee with recent date:

10 A AAA Nov 10, 2005
20 B BBB DEC 10, 2005

Thanks for the help in advance. Paul
Reply With Quote
  #2 (permalink)  
Old 02-07-06, 01:47
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
How about:

SELECT ID,Name,Project_Name, MAX(Date)
From Employee
GROUP BY ID, Name, Project_Name
Reply With Quote
  #3 (permalink)  
Old 02-09-06, 11:37
ihendr ihendr is offline
Registered User
 
Join Date: Mar 2005
Posts: 7
if your table contains more columns or its cardinality is different then your example, you might want to try this

select * from
(select
ID,
Name,
Project_Name,
Date,
row_number() over (partition by ID order by date desc) as x
from Employee) T1
where T1.x = 1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On