Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

problems with picking up the latest record..

 
   Database Forums (Home) -> Oracle RSS
Next:  accessing mysql using ssl  
Author Message
Deepu




Joined: Sep 02, 2005
Posts: 2



(Msg. 1) Posted: Tue Sep 13, 2005 1:19 am
Post subject: problems with picking up the latest record..

Hi,
I have a table in my database which has a date column...I need to pick up a resultset based on a where clause, identify the latest record based on the date column and then go ahead and pick up other values of the latest record. Here is the rough structure of the query..How could we use max with a date??..or could we do an order by...desc and pick up the first record??..Please help..

select bill_nbr from bill_table
where (bill_date is the most recent.)

Thanks in Advance.
Deepu.

 >> Stay informed about: problems with picking up the latest record.. 
Back to top
Login to vote
Deepu




Joined: Sep 02, 2005
Posts: 2



(Msg. 2) Posted: Tue Sep 13, 2005 4:33 am
Post subject: Re: problems with picking up the latest record.. [Login to view extended thread Info.]

HI,
Got the answer by myself..

select bill_nbr from (select bill_nbr from bill_table order by update_date desc) temp where rownum < 2.

do write in your replies too...

Thanks a lot,
Deepu.

 >> Stay informed about: problems with picking up the latest record.. 
Back to top
Login to vote
user1786

External


Since: Dec 06, 2004
Posts: 141



(Msg. 3) Posted: Tue Sep 13, 2005 11:32 am
Post subject: Re: problems with picking up the latest record.. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Deepu wrote:
> "Deepu" wrote:
> > Hi,
> > I have a table in my database which has a date column...I need
> > to pick up a resultset based on a where clause, identify the
> > latest record based on the date column and then go ahead and
> > pick up other values of the latest record. Here is the rough
> > structure of the query..How could we use max with a date??..or
> > could we do an order by...desc and pick up the first
> > record??..Please help..
> >
> > select bill_nbr from bill_table
> > where (bill_date is the most recent.)
> >
> > Thanks in Advance.
> > Deepu.
> > [color=blue:f44f5a1408][/color:f44f5a1408]
>
> HI,
> Got the answer by myself..
>
> select bill_nbr from (select bill_nbr from bill_table order by
> update_date desc) temp where rownum < 2.
>
> do write in your replies too...
>
> Thanks a lot,
> Deepu.

You had the answer in your own first post:
> How could we use max with a date??..

Why not try it and find out? Since you seem to like inline views try
this:

select bill_nbr from
( select max(update_date) latest from bill_table ) temp,
bill_table
where temp.latest = bill_table.update_date ;

Stop thinking in terms of files and start thinking in terms of the
data. ROWNUM is a crutch. Avoid it whenever possible. What made you
think MAX() could not be used on a DATE column? It works fine on dates,
number, even text columns.

And for kicks here's another way to phrase this query:

select bill_nbr from bill_table
where update_date in
( select max(update_date) latest from bill_table ) ;

So use ROWNUM only as a last resort. It seldom is the best solution.

HTH,
Ed
 >> Stay informed about: problems with picking up the latest record.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
"Hands on training" requirement for latest OCA/OCP certifi.. - Read briefly on Oracle's web site that they've added a "hands-on" training requirement to the OCA/OCP certs... to "enhance their value" or some such. My question is this: is this a revenue enhancement upgrade, meaning must one take O...

Find the first record, for every day - Hi ! I have a tricky problem, and i can't solve it. I have the following table T1, with the following fields and records: Date_ Status ---------- ------- 2005-12-01 2 2005-12-01 1 2005-12-17 1 2005-12-18 2 2005-12-18 10 I want to generate...

Record and Raw types - HI I've got a simple structure like the following: DECLARE TYPE LOGON_PACKET IS RECORD( szUsername CHAR(256), szPwdEnc CHAR(256)); logonPKT LOGON_PACKET; and when I call ret_val := utl_tcp.write_raw(c,logonPKT); I get type mismatch error..

SqlNet problems - Hi there, we are facing problems and dont know what caused them We have an application server on win2k3 with 9i thiick client and then database server 10G Rac on HP-UX, we receive errors like ORA-03113: end-of-file on communication channel Do you..

Copy a record from 1-table to another - Greetings... This is an extremely simplified version of the actual problem, just to make it easier. I have 2-tables: R(a) and S(a,b) I want to do the following (which doesn't work), and I don't know what I need to do to make it work. This is on a..
   Database Forums (Home) -> Oracle All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]