Hi everyone,
I am working on Oracle 11g DB and i am using plsql allround automation tool. I am trying to pull some unique records from a list of duplicates based on the date but i ran into a issue where the timing is also same for the same request id's
Example:
create table temp
(request_id varchar2(50),
created_date date,
Status varchar2(50));
insert into temp(request_id,created_date,status) values ('CF-0000001',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'For Review');
insert into temp(request_id,created_date,status) values ('CF-0000001',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'Completed');
insert into temp(request_id,created_date,status) values ('CF-0000112',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'For Review');
insert into temp(request_id,created_date,status) values ('CF-0000113',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'For Review');
insert into temp(request_id,created_date,status) values ('CF-0000114',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'Completed');
insert into temp(request_id,created_date,status) values ('CF-0000115',to_date('08/26/2009 13:07:01','MM/DD/YYYY HH24:MI:SS'),'Completed');
select * from temp;
| REQUEST_ID | STATUS | CREATED_DATE |
1 | CF-0000001 | For Review | 8/26/2009 1:07:01 PM |
2 | CF-0000001 | Completed | 8/26/2009 1:07:01 PM |
3 | CF-0000112 | For Review | 8/26/2009 1:07:01 PM |
4 | CF-0000113 | For Review | 8/26/2009 1:07:01 PM |
5 | CF-0000114 | Completed | 8/26/2009 1:07:01 PM |
6 | CF-0000115 | Completed | 8/26/2009 1:07:01 PM |
Now if i tried to pull the unique request id,status code based on the complete date then i wrote a query like this
select t.request_id, t.Status, t.created_date
from temp t
inner join (select request_id,
max(created_date) as MaxDate
from temp
group by request_id) tm
on t.request_id = tm.request_id
and t.created_date = tm.MaxDate
order by t.request_id
| REQUEST_ID | STATUS | CREATED_DATE |
1 | CF-0000001 | For Review | 8/26/2009 1:07:01 PM |
2 | CF-0000001 | Completed | 8/26/2009 1:07:01 PM |
3 | CF-0000112 | For Review | 8/26/2009 1:07:01 PM |
4 | CF-0000113 | For Review | 8/26/2009 1:07:01 PM |
5 | CF-0000114 | Completed | 8/26/2009 1:07:01 PM |
6 | CF-0000115 | Completed | 8/26/2009 1:07:01 PM |
AS you can see the request id 'CF-0000001' is showing twice, i know that the created date time is same and that's why it is showing up.
So my question is, is there any way that i can pull only unique record (doesn't matter which status) or can we completely remove those kind of request id's ?? I tried googling this kind of issue and i found a similar one but i didn't the correct answer (sql - How to return only 1 row if multiple duplicate rows and still return rows that are not duplicates? - Stack Overflo… )Query help