Re: Query Problem..
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 08:55:42 -0400
You need to change both joins to LEFT.
AJ wrote:
Hi Bob,
Thanks for the reply...!
Another quick question though...
I need to change the JOIN between company & sale from an 'INNER JOIN'
to a 'LEFT JOIN'. Access won't support it. Is their another way to
construct this query to acheive this???
Regards,
Adam
"Bob Barrows [MVP]" wrote:
AJ wrote:
Hi all,I can't test it, but try this:
I am trying to execute the following query:
SELECT
c.ID, c.Company_Name,
(SELECT Max(ID) FROM Sale s WHERE s.Company_ID = c.ID) AS
LastSaleID, (SELECT s.Package_ID FROM Sale s WHERE s.ID =
LastSaleID) AS PackageID
FROM
Company AS c
My problem is, 'LastSaleID' isn't picked up as a column in of the
main query in the second sub query. If i was to use another column
in the main query this problem dissappears.
I am unfortunatel using Access; any help appreciated to get this to
work as needed.
SELECT
c.ID, c.Company_Name,
s.LastSaleID,
p.PackageID
FROM
(Company AS c INNER JOIN
(SELECT Company_ID, Max(ID) AS LastSaleID FROM Sale
GROUP BY Company_ID) As s
ON s.Company_ID = c.ID) INNER JOIN
Sale p ON p.ID = s.LastSaleID
If Access complains about the subquery in thre FROM clause, create a
saved query called MaxIDPerCompany with this sql:
SELECT Company_ID, Max(ID) AS LastSaleID FROM Sale
GROUP BY Company_ID
And change the above query to:
SELECT
c.ID, c.Company_Name,
s.LastSaleID,
p.PackageID
FROM
(Company AS c INNER JOIN
MaxIDPerCompany As s
ON s.Company_ID = c.ID) INNER JOIN
Sale p ON p.ID = s.LastSaleID
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- References:
- Re: Query Problem..
- From: Bob Barrows [MVP]
- Re: Query Problem..
- From: AJ
- Re: Query Problem..
- Prev by Date: Re: Query Problem..
- Next by Date: problem invoking stored procedure
- Previous by thread: Re: Query Problem..
- Next by thread: problem invoking stored procedure
- Index(es):
Relevant Pages
|