Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: HELP new to sql min query
Hi,
I think you're missing some joins here. I presume there is a foreign key between rental and cust. In the following example I guess this column to be named custno. In that case something like this should work:
select c.cname
from cust c, rental r
where r.custno = c.custno
and (r.milesin - r.milesout) = (select min(r1.milesin - r1.milesout)
from rental r1);
Beware, that the query could return more than 1 row - that is if milesin-milesout ar the same for more customers.
Hope this helps.
Regards,
Michael Ringbo
Chris wrote:
> I am trying to return the name value from one table where it equals a min
> amout in another code below but it always come back no rows selected can
> anyone help as i am new to sql
>
> select cname from cust, rental
> where cname in (select min(milesin - milesout) from rental;
Received on Tue Feb 23 1999 - 05:24:13 CST