问题
I have a question on subqueries in advantage. As I was analyzing several SQL queries I stumbled upon a strange situation.
When I executed the following SQL, I got these results:
select *
from orderlyn
where OLWArtnr in (select OlwArtnr from prijs)
But OlwArtNr doesn’t exist in the table Prijs.
CREATE TABLE Prijs (
Nummer Char( 20 ),
Lijst Char( 15 ),
Verkprijs Double( 0 ),
Aankprijs Double( 0 ),
BTW Char( 2 ),
Naam1 Char( 30 ),
Naam2 Char( 30 ),
Naam3 Char( 30 ),
Naam4 Char( 30 ),
Vervangnr Char( 20 ),
Kortcode Char( 10 ),
Datum Date,
Vpeuro Double( 0 ),
A1 Char( 20 )) IN DATABASE;
What worried me most of all, is the fact that it gives different results, when I used select nummer from prijs
as subquery.
Why does advantage gives me results, when the column doesn’t even exist inside the other table? I think it should give an error.
If advantage is making interpretations, on which parameters is it doing this?
回答1:
This is not a bug. It is working correctly.
The OlwArtnr in the subquery, when not fully qualified, resolves to the OlwArtnr column in the parent query. Unqualified column in the subquery is resolved using the table in the subquery first. If it is not one of the columns from the tables in the subquery, it will go to the parent query, using the tables in the parent query. This process continues up the chain until either the column resolves to a table or an error is generated.
You will get the same with SQLServer or other database.
来源:https://stackoverflow.com/questions/9887251/problems-with-subquery-field-doesnt-exist-but-advantage-is-giving-me-results