Subject RE: [firebird-support] Similar SQL query fails
Author Rick Debay
Good eye! Changing it to this works! Thanks!

select
d.PRODUCTID, (d.AWP / d.QTY) awp_ppu, d.GPI, d.PRODUCTID/100 ndc9
from MDDB_DRUG d where d.GPI = ? and d.PRODUCTID/100 = ? and
(d.AWP / d.QTY) <= ALL(
select MIN( d2.AWP / d2.QTY )
from MDDB_DRUG d2
where d.PRODUCTID/100 = d2.PRODUCTID/100 and d.GPI = d2.GPI
)

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Arno Brinkman
Sent: Friday, January 27, 2006 6:23 PM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Similar SQL query fails

Hi,

> The first query uses the same table in both the select and the
> sub-select.
> The second working query uses the same view in both the select and the

> sub-select.
>
> How is this different?

In the first query you reference to the "master" relation and in the
second query to the sub-relation.

<snip>
FROM
MDDB_DRUG d
WHERE

<snip>
select MIN( d.AWP / d.QTY )
from MDDB_DRUG d2

Inside the MIN you reference to table wit alias d instead of table with
alias d2

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
General database development support:
http://www.databasedevelopmentforum.com

Firebird open source database (based on IB-OE) with many SQL-99 features
:
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Firebird and Interbase users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://firebird.sourceforge.net and click the Resources item on
the main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yahoo! Groups Links