RE: SQL subquery question

From: Ken Atkins <katkins_at_iccom.com>
Date: 1996/05/16
Message-ID: <01bb434e.e30fe380$0905eecd_at_katkins.iccom.com>#1/1


I would do something like:

SELECT po, time, customer (or whatever)

   FROM tableCustomer tc, tablePO po
  WHERE tc.customer = po.customer
    AND po.time =
(SELECT MAX(po2.time)

   FROM tablePO po2
  WHERE po2.customer = tc.customer
)



Ken Atkins - Oracle Programmer/Analyst (katkins_at_iccom.com)

In an effort to contribute some content to the Web I have created an 'Oracle Hint of the Week' site:

   http://www.iccom.com/usrwww/katkins/orahint.htm

Check it out!


   

On Thursday, May 16, 1996, Albert Yu wrote...
> I am having a problem with using SQL subquery.
> What I want to do is the following: Given a table of customers and a
> related
> table of purchase orders, I want to find
> every customer's latest purchase order by date and time.
> So what I have now in my subquery is:
>
> select * from tableCustomer x where
> time = (select max(time) from tablePO y where x.customer=
> y.customer and y.run_date= (select max(date) from tablePO z where
> y.customer= z.customer group by customer) group by x.customer)
>
>
> I am not sure if I made an error in the sql statement because I am not
> getting
> all the latest entries coming out.
>
> Or might there be a better way of doing this query.
>
> Thanks in advance,
> --
> Albert Yu NORTEL
> EMAIL: ayu_at_nortel.ca
>
Received on Thu May 16 1996 - 00:00:00 CEST

Original text of this message