Re: INNER JOIN Using ADOQuery



"eddela" <llcrcaero@xxxxxxxxx> wrote in message
news:442bec8b$1@xxxxxxxxxxxxxxxxxxxxxxxxx
In a small App, I am using an ADOQuery component to inner join two
MSAccess tables and do a query involving fields from both tables. The SQL
property of the ADOQuery has this statement.

SELECT Item, Description, Vendor FROM Table1, Table2

WHERE Table1.Item = Table2.Item

This statement is right out of the text book, yet the following error
message appears. "The specified field 'Item' could refer to more than one
table listed in the FROM clause of your SQL statement."

Of course it does, but why is the exception raised? Please help. Thanks

You and I know that it doesn't matter which table the Item field comes from,
but the parser doesn't and is incapable of making such a decision. Always
be specific about which table a field comes from, even when there's
currently no question. Table layouts have a habit of changing, even in
seemingly trivial applications.

SELECT t1.Item, t2.Description, t2.Vendor FROM Table1 t1, Table2 t2 WHERE
t1.Item = t2.Item;

"Eschew Ambiguity". :)

--
Ray Marron


.



Relevant Pages

  • TADOQuery and TDateTime Field Query
    ... I have a puzzling problem with a query using a TADOQuery component. ... when I execute the following SQL against the same MSAccess 2002 database I get an error: ...
    (borland.public.delphi.database.ado)
  • SQL queries that have parameters passed by user
    ... the criteria dynamically either through the web or from MSAccess or ... The query also does a GROUP BY the state and other variables that are ... I know how to get MSAccess and asp pages to do the sorting and ... selecting against an SQL tbl or view, but when access queries the same ...
    (comp.databases.ms-sqlserver)
  • Re: Item cannot be found in the collection corresponding to the requested name or ordinal
    ... > What happens when you copy the sql into a Query in MSAccess? ... Paste the completed SQL here so we can take a look. ... You are doing some interesting joins - perhaps if you also posted your query ... complaining about a join sub-collection. ...
    (microsoft.public.vb.database.ado)
  • Re: SQL queries that have parameters passed by user
    ... all my sql work was done through the Enterprise ... several fields and filters on a criteria that I would like to be user ... The query works fine in MS SQL and seems to be fairly quick, ... >> the criteria dynamically either through the web or from MSAccess or ...
    (comp.databases.ms-sqlserver)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)