Re: Help with derived table SQL statement in Access
- From: "Chris2" <rainofsteel.NOTVALID@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Jun 2007 18:02:03 -0700
"Andrew" <andrewmrichards@xxxxxxxxxxx> wrote in message
news:1181660751.467152.258130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 12, 2:44 pm, "Chris2"below).
<rainofsteel.NOTVA...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"Andrew" <andrewmricha...@xxxxxxxxxxx> wrote in message
news:1181646621.996165.249640@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All
<snip>
Andrew,
<snip>
Hi Chris
Thanks for your input.
I've amended the query as you suggest (resultant SQL is pasted
As far as I'm aware, although Access does use the table alias beforeit
every column name, it's not actually needed, and so I often remove
for clarity, without ill effect...
Andrew,
Table aliases increase the clarity of SQL by explicitly noting each
column's origin table. Explicit code is preferred to implicit code.
All of which leads me to.... nothing new! Unfortunately, it still
doesn't work. A minor error in what I said first time is that if you
don't enter a value in the parameter inputbox, you get all those
labels which don't have a matching contact at all, rather than no
output.
If I remove the where clause from the subquery, it works, but I get
all the contacts, not just the first one...
<snip>
<sigh> Is understanding too much to ask of life?!
Andrew
<code snip>
I tried to replicate your issue in general.
ItemMaster and PricingMaster are two simple example tables I keep
around in one of my databases, their structure is not important for
this example.
SELECT *
FROM ItemMaster AS IM1
LEFT JOIN
(SELECT *
FROM PricingMaster as PM0
WHERE IM1.ItemID = PM0.ItemID
ORDER BY 1) AS PM1
ON IM1.ItemID = PM1.ItemID
When I try to run this query, MS Access throws a parameter input box
and wants a parameter for IM1.ItemID.
When I take out the WHERE, the issue goes away.
This seems to be exactly what is happening to you.
While you can "create" a table (as a table expression) by using a
SELECT expression on the FROM clause, but that is just that, a table
expression (a full query), I am thinking you cannot do correlation
between two table-type expressions on the FROM clause. If you had a
subquery in the table-type expression, you might swing correlation,
but I'm not sure.
A reading of the JET SQL 4.0 Reference "SQL Subqueries", seems to
vaguely suggest it as well.
--------------------------
Syntax
You can use three forms of syntax to create a subquery:
comparison [ANY | ALL | SOME] (sqlstatement)
expression [NOT] IN (sqlstatement)
[NOT] EXISTS (sqlstatement)
--------------------------
And:
--------------------------
You can also use table name aliases in a subquery to refer to tables
listed in a FROM clause outside the subquery. The following example
returns the names of employees whose salaries are equal to or greater
than the average salary of all employees having the same job title.
The Employees table is given the alias "T1":
SELECT LastName,
FirstName, Title, Salary
FROM Employees AS T1
WHERE Salary >=
(SELECT Avg(Salary)
FROM Employees
WHERE T1.Title = Employees.Title) Order by Title;
In the preceding example, the AS reserved word is optional.
--------------------------
It doesn't come right out and say it, but I believe that correlation
may not be possible between two table expressions on the FROM clause.
(My belief may be incorrect, of course. It just appears that way from
this.)
Sincerely,
Chris O.
.
- Follow-Ups:
- Re: Help with derived table SQL statement in Access
- From: Andrew
- Re: Help with derived table SQL statement in Access
- References:
- Help with derived table SQL statement in Access
- From: Andrew
- Re: Help with derived table SQL statement in Access
- From: Chris2
- Re: Help with derived table SQL statement in Access
- From: Andrew
- Help with derived table SQL statement in Access
- Prev by Date: Re: Split a full name field (comma separated) into two fields
- Next by Date: Obtaining Count of Records and Placing in Report
- Previous by thread: Re: Help with derived table SQL statement in Access
- Next by thread: Re: Help with derived table SQL statement in Access
- Index(es):
Relevant Pages
|