Re: SQL example: What's the difference?
Posted in 1996
Topics: SQL Development & Query Writing
Armando Suarez Cueto wrote:
>
> I run these two select statements that I think are equivalent but the results are
> different!
>
> What is wrong in 1?
> 1)
> select p.numpieza, nompieza
> from pieza p, preciosum ps
> where p.numpieza=ps.numpieza
> group by p.numpieza, nompieza
> having avg(preciounit)>=all
> (select max(preciocompra)
> from linped
> where linped.numpieza=p.numpieza)>
> 2) This is the correct:
>
> select p.numpieza, nompieza
> from pieza p, preciosum ps
> where p.numpieza=ps.numpieza
> group by p.numpieza, nompieza
> having avg(preciounit)>=
> (select max(preciocompra)
> from linped
> where linped.numpieza=p.numpieza)>
--
It's possible that subclose
all (select max(preciocompra)
from linped
where linped.numpieza=p.numpieza)
results row with <null> in differnce to
(select max(preciocompra)
from linped
where linped.numpieza=p.numpieza)
that produce 0 always.
It must be concerned how the system compares
things with <null>
May be it's strictly dependent on platform. What is the?
really i'm slightly confused
-------------------------------------------
Maksim I. Aniskov man@sice.nsk.su
----- Novosibirsk ------------ Russia -----
SICE - Siberian Interbank Currency Exchange
-------------------------------------------