Hi List,

I found the answer to my query myself and here goes the solution:

select x.* from (select 'shipment' table_name,ce.display_name,st.timestamp,
sequence 
from shipment_timestamp st, customer_event ce, xm_field xm 
where shipment_id = 10402344721477 
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and st.event_id = xm.event_id
union
select 'container' table_name,ce.display_name,sct.timestamp, sequence  
from shipment_container_timestamp sct, customer_event ce, xm_field xm 
where shipment_id = 10402344721477 
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and sct.event_id = xm.event_id
union
select 'order' table_name,ce.display_name,ot.timestamp, sequence  
from order_timestamp ot, shipment_order so,customer_event ce, xm_field xm 
where so.shipment_id = 10402344721477 
and so.order_id = 2
and ot.shipment_order_id = so.shipment_order_id  
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and ot.event_id = xm.event_id 
) x where x.sequence = ( select max(sequence) from 
(select 'shipment' table_name,ce.display_name,st.timestamp, sequence 
from shipment_timestamp st, customer_event ce, xm_field xm 
where shipment_id = 10402344721477 
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and st.event_id = xm.event_id
union
select 'container' table_name,ce.display_name,sct.timestamp, sequence  
from shipment_container_timestamp sct, customer_event ce, xm_field xm 
where shipment_id = 10402344721477 
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and sct.event_id = xm.event_id
union
select 'order' table_name,ce.display_name,ot.timestamp, sequence  
from order_timestamp ot, shipment_order so,customer_event ce, xm_field xm 
where so.shipment_id = 10402344721477 
and so.order_id = 2
and ot.shipment_order_id = so.shipment_order_id  
and ce.CUSTOMER_MOT_ID = 1040130035205
and xm.field_id = ce.field_id
and ot.event_id = xm.event_id))

My apologies for posting such a long query to the forum.

Thanks and Regards,

Ranganath


> -----Original Message-----
> From: Krishnaswamy, Ranganath 
> Sent: Wednesday, January 29, 2003 5:59 PM
> To:   Multiple recipients of list ORACLE-L
> Subject:      Return the first row only
> 
> Hi List,
> 
> I have the below query which returns 13 records.  In this I want to
> display
> only the 1st row.  Is it possible to do this through rownum or any other
> function or pseudo column?  If so, please let me know the same.  Any help
> in
> this regard is very much appreciated.
> 
> select 'shipment' table_name,ce.display_name,st.timestamp, sequence 
> from shipment_timestamp st, customer_event ce, xm_field xm 
> where shipment_id = 10402344721477 
> and ce.CUSTOMER_MOT_ID = 1040130035205
> and xm.field_id = ce.field_id
> and st.event_id = xm.event_id
> union
> select 'container' table_name,ce.display_name,sct.timestamp, sequence  
> from shipment_container_timestamp sct, customer_event ce, xm_field xm 
> where shipment_id = 10402344721477 
> and ce.CUSTOMER_MOT_ID = 1040130035205
> and xm.field_id = ce.field_id
> and sct.event_id = xm.event_id
> union
> select 'order' table_name,ce.display_name,ot.timestamp, sequence  
> from order_timestamp ot, shipment_order so,customer_event ce, xm_field xm 
> where so.shipment_id = 10402344721477 
> and so.order_id = 2
> and ot.shipment_order_id = so.shipment_order_id  
> and ce.CUSTOMER_MOT_ID = 1040130035205
> and xm.field_id = ce.field_id
> and ot.event_id = xm.event_id order by sequence desc 
> 
> Thanks and Regards,
> 
> Ranganath
> WARNING: The information in this message is confidential and may be
> legally
> privileged. It is intended solely for the addressee.  Access to this
> message
> by anyone else is unauthorised.  If you are not the intended recipient,
> any
> disclosure, copying, or distribution of the message, or any action or
> omission taken by you in reliance on it, is prohibited and may be
> unlawful.
> Please immediately contact the sender if you have received this message in
> error. Thank you.
> -- 
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> -- 
> Author: Krishnaswamy, Ranganath
>   INET: [EMAIL PROTECTED]
> 
> Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
> San Diego, California        -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like subscribing).
WARNING: The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee.  Access to this message
by anyone else is unauthorised.  If you are not the intended recipient, any
disclosure, copying, or distribution of the message, or any action or
omission taken by you in reliance on it, is prohibited and may be unlawful.
Please immediately contact the sender if you have received this message in
error. Thank you.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Krishnaswamy, Ranganath
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to