Re: subquery
- From: "Rohan" <zulander@xxxxxxxxx>
- Date: 9 Aug 2006 10:29:39 -0700
Let me explain it to you
i have a table that keeps records of Transerfers by dates, Start
Address and Destinatin Address, in this table there are item that can
be transfered from one place to another i want to select all the item
by group but with the recent dates
i made this SQL, For some reaon The Current address is not coresponding
it is giving me a nother address, it seems that it is sorting by
lastest date thank you
SELECT DISTINCT Last([transport de generatrice].ID) AS LastOfID,
[transport de generatrice].Nom, Last([transport de
generatrice].UpdateDate) AS LastOfUpdateDate, Last([BU
details_1].[Alpha name]) AS [Primary Address],
Last(CurrentAddress([transport de generatrice]![Destination_Add],[BU
details]![Alpha name],Nz([transport de
generatrice]![Destination_add_sec],""))) AS CurentADD
FROM (([transport de generatrice] INNER JOIN [BU details] ON [transport
de generatrice].Destination_Add = [BU details].BU) INNER JOIN
Generatrice ON [transport de generatrice].Nom = Generatrice.Nom) INNER
JOIN [BU details] AS [BU details_1] ON Generatrice.Primary_Location_ID
= [BU details_1].BU
GROUP BY [transport de generatrice].Nom
ORDER BY Last([transport de generatrice].ID);
Gary Walter wrote:
You can use a subquery (without an ending ";" and
an ORDER BY clause is superfluous) in a
SELECT clause,
FROM clause,
or WHERE clause.
In the SELECT clause, the subquery must provide
only "one result," i.e., only one field and only one value
for that one field.
You can "correlate" the subquery back to the main
query so that "one result" is different depending
on a field (or fields) in the main query.
What are you trying to return from the subquery?
How does the subquery relate back to the main query,
i.e., for every record in the main query, what "one result"
do you want to include from a subquery, and how is that
value arrived at in some relation between the subquery
and the main query?
Without seeing your data, I am at a loss to understand
what you are trying to do...sorry. So, my best *guess* is
that you want to save the first query, then add this query
to the second query "as a table" joining on "MaxOfID"
to return the Nom?
This "divide and conquer" method of saving queries to be
used in further processing will always prove more useful
(vs subqueries) until you understand SQL better. I think
I understand SQL well, but I am still comfortable in saving
queries with well-defined names to be used in this
"divide-and-conquer" manner.
"Rohan" wrote:
Hi this is my subquery that i have: which doesn't work :
SELECT(SELECT Max([transport de generatrice].ID) AS MaxOfID,
Generatrice.Nom
FROM (([BU details] INNER JOIN Generatrice ON [BU details].BU =
Generatrice.Primary_Location_ID) INNER JOIN [transport de generatrice]
ON Generatrice.Nom = [transport de generatrice].Nom) INNER JOIN [BU
details] AS [BU details_1] ON [transport de
generatrice].Destination_Add = [BU details_1].BU
GROUP BY Generatrice.Nom ORDER BY Max([transport de generatrice].ID)
DESC;) , [transport de generatrice].*, IIf([transport de
generatrice]![Destination_Add]="40000",[transport de
generatrice]![Destination_add_sec],[BU details]![Alpha name]) AS
Adresse
FROM ([Invent_Gen ollie] LEFT JOIN [transport de generatrice] ON
[Invent_Gen ollie].MaxOfID = [transport de generatrice].ID) LEFT JOIN
[BU details] ON [transport de generatrice].Destination_Add = [BU
details].BU;
I made this query by combining two queres
frist:
SELECT Max([transport de generatrice].ID) AS MaxOfID, Generatrice.Nom
FROM (([BU details] INNER JOIN Generatrice ON [BU details].BU =
Generatrice.Primary_Location_ID) INNER JOIN [transport de generatrice]
ON Generatrice.Nom = [transport de generatrice].Nom) INNER JOIN [BU
details] AS [BU details_1] ON [transport de
generatrice].Destination_Add = [BU details_1].BU
GROUP BY Generatrice.Nom
ORDER BY Max([transport de generatrice].ID) DESC;
Second :
SELECT
[transport de generatrice].*, IIf([transport de
generatrice]![Destination_Add]="40000",[transport de
generatrice]![Destination_add_sec],[BU details]![Alpha name]) AS
Adresse
FROM ([Invent_Gen ollie] LEFT JOIN [transport de generatrice] ON
[Invent_Gen ollie].MaxOfID = [transport de generatrice].ID) LEFT JOIN
[BU details] ON [transport de generatrice].Destination_Add = [BU
details].BU;
i am getting the fallowing error :
You have written a subquery that can return more than one field without
using the EXISTS reserved word in the main query's FROM clause. Revise
the SELECT statement of the subquery to request only one field. (Error
3306)
Thank you for your help !
.
- Follow-Ups:
- Re: subquery
- From: Gary Walter
- Re: subquery
- From: Michel Walsh
- Re: subquery
- References:
- subquery
- From: Rohan
- Re: subquery
- From: Gary Walter
- subquery
- Prev by Date: Re: Join Problem
- Next by Date: Re: Query Return Reocrds for only the current Date.
- Previous by thread: Re: subquery
- Next by thread: Re: subquery
- Index(es):
Relevant Pages
|
|