dbTalk Databases Forums  

build table from "logging" table, one row per user - oldest date

comp.databases.oracle.server comp.databases.oracle.server


Discuss build table from "logging" table, one row per user - oldest date in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
okey
 
Posts: n/a

Default build table from "logging" table, one row per user - oldest date - 09-16-2010 , 06:37 PM






I have a “logging” table. It records the user, login time, and other
things.

I want to create table within a statement that returns one row for
each user. This row is the row containing the user’s oldest date

Select blah blah from table x, (select user, date, other, info from
logging where date is max) oldrows
where x.date < oldrows.date
and x.user = oldrows.user

It’s building the table here that looks very difficult. This would be
easy enough to do in pl/sql, but I rather do it this way, if it can
even be done. This kind of thing is going to come up a lot.

Thank you

Reply With Quote
  #2  
Old   
okey
 
Posts: n/a

Default Re: build table from "logging" table, one row per user - oldest date - 09-16-2010 , 07:00 PM






On Sep 16, 6:37*pm, okey <oldyor... (AT) yahoo (DOT) com> wrote:
Quote:
I have a “logging” table. *It records the user, login time, and other
things.

I want to create table within a statement that returns one row for
each user. *This row is the row containing the user’s oldest date

Select blah blah from table x, (select user, date, *other, info from
logging where date is max) oldrows
where x.date < oldrows.date
and x.user = oldrows.user

It’s building the table here that looks very difficult. *This would be
easy enough to do in pl/sql, but I rather do it this way, if it can
even be done. This kind of thing is going to come up a lot.

Thank you
I thought this might be a way, another subselect to find max date.
As in:

select blah, blah from logtable t, (select distinct user, max(date)
group by user) mx where mx.user = t.user ...

I'd have to assume the distinct user date was indeed unique. Not
there yet unless I create yet another subselect to select that max
date record and group it with a max unique key - any one would do.

You'd think there was something better.

Reply With Quote
  #3  
Old   
ddf
 
Posts: n/a

Default Re: build table from "logging" table, one row per user - oldest date - 09-17-2010 , 08:01 AM



On Sep 16, 8:00*pm, okey <oldyor... (AT) yahoo (DOT) com> wrote:
Quote:
On Sep 16, 6:37*pm, okey <oldyor... (AT) yahoo (DOT) com> wrote:





I have a “logging” table. *It records the user, login time, and other
things.

I want to create table within a statement that returns one row for
each user. *This row is the row containing the user’s oldest date

Select blah blah from table x, (select user, date, *other, info from
logging where date is max) oldrows
where x.date < oldrows.date
and x.user = oldrows.user

It’s building the table here that looks very difficult. *This wouldbe
easy enough to do in pl/sql, but I rather do it this way, if it can
even be done. This kind of thing is going to come up a lot.

Thank you

I thought this might be a way, another subselect to find max date.
As in:

select blah, blah from logtable t, *(select distinct user, max(date)
group by user) mx where mx.user = t.user ...

I'd have to assume the distinct user date was indeed unique. *Not
there yet unless I create yet another subselect to select that max
date record and group it with a max unique key - any one would do.

You'd think there was something better.- Hide quoted text -

- Show quoted text -
Who can say siince you haven't posted a create table statement and
some sample data. We have no idea what your data looks like so how
can we suggest an alternative?


David Fitzjarrell

Reply With Quote
  #4  
Old   
shakespeare
 
Posts: n/a

Default Re: build table from "logging" table, one row per user - oldest date - 09-17-2010 , 12:47 PM



Op 17-9-2010 1:37, okey schreef:
Quote:
I have a “logging” table. It records the user, login time, and other
things.

I want to create table within a statement that returns one row for
each user. This row is the row containing the user’s oldest date

Select blah blah from table x, (select user, date, other, info from
logging where date is max) oldrows
where x.date< oldrows.date
and x.user = oldrows.user

It’s building the table here that looks very difficult. This would be
easy enough to do in pl/sql, but I rather do it this way, if it can
even be done. This kind of thing is going to come up a lot.

Thank you

select user, min(login_time)
from x
group by user

?

Shakespeare

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.