Re: Get 10 latest customers

From: My-Phuong L Tran <mtran2_at_osf1.gmu.edu>
Date: 1995/05/13
Message-ID: <3p2lvu$ibr_at_portal.gmu.edu>#1/1


In article <3p09h1$9pl_at_ns1.unicomp.net> thrash_at_delphi.onramp.net (David R. Thrash) writes:
>
>
>This is database 101 - n'est pas?
>
>Select Customer_Code
> from BOOKING b1
> where 10 <= (select count(*)
> from BOOKING b2
> where b2.Transaction_date > b1.Transaction_date)
>/
>

After some slight corrections,

  Select Customer_Code
    from BOOKING b1
  where 10 >= (select count(*)

                 from BOOKING b2
               where b2.Transaction_date >= b1.Transaction_date)

Although this a slick solution, there may be problems of interpretation in the context of the relational model. One way to see this (I think) is try the substitution of

(1) "...10 >= (select..." by

(2) "...10 = (select..."

The second select statement only returns 1 row, *not* 10. It seems that the interpretation of the select statement is dependent on the algorithm that Oracle uses in interpreting general select statements, i.e. the subquery typically being independent of the main query. Does anyone know the 'correct' interpretation of select statements in which there are dependencies between main queries and sub queries?

Best,

Ted Karas Received on Sat May 13 1995 - 00:00:00 CEST

Original text of this message