Oracle DB SQL: record with user_id, name and oldest time stamp (show only oldest time stamp)

Oracle DB SQL: record with user_id, name and oldest
time stamp (show only oldest time stamp)

Hi Sven

On 23/03/11 11:35, Sven Aluoor wrote:

SQL statement:

SELECT user_id, jc_name, upd_time
FROM user_jc
WHERE user_id IN ( SELECT user_id
FROM user_jc
WHERE JC_NAME LIKE 'PPF_S_%' ESCAPE ''
GROUP BY user_id
HAVING COUNT (user_id)> 1)
AND JC_NAME LIKE 'PPF_S_%' ESCAPE ''
GROUP BY user_id, jc_name, upd_time

I'm thinking, but I've not tested, this:

SELECT user_id, jc_name, MIN(upd_time)
...
GROUP BY user_id, jc_name;

--
Cheers,
Norm. [TeamT]

On Fri, Mar 25, 2011 at 12:46 PM, Norman Dunbar wrote:

Hi Sven
I'm thinking, but I've not tested, this:

SELECT user_id, jc_name, MIN(upd_time)
...
GROUP BY user_id, jc_name;

Thanks, but I tried this already. Doesn't work.

cheers Sven

SELECT user_id, jc_name, MIN(upd_time)

It must be Fri and I must still be asleep… for just an instant, 1/10th of
a second kind-of-thing, I thought:

He said oldest, it should be max…

:slight_smile:

Roger S.

This works for me on a limited data set:

select user_id,jc_name,upd_time
from (
– begin inner bit
select user_id, jc_name, upd_time,
row_number() over (partition by user_id order by
user_id,jc_name,upd_time) as ranking
from user_jc
where jc_name like ‘PPF_S_%’ escape ‘’
)
– end inner bit
where ranking = 1
order by user_id;

Hopefully Yahoo/Outlook won’t destroy the formatting!

Cheers,
Norm. [TeamT]

Norman Dunbar
Contract Senior Oracle DBA
Capgemini Database Team (EA)
Internal : 7 28 2051
External : 0113 231 2051

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk