Solved Combining Two Queries Into One (1 Viewer)

HardWorking

New member
Local time
Today, 04:02
Joined
Apr 13, 2020
Messages
8
Yesterday I got help with a sub query I was having a lot of trouble with and it works great using two queries.Today I would like to
combine the 2 queries into one. I have tried several things but I keep getting something wrong. Can someone
please show me what I am doing wrong? Thank you very much.

Yesterday's two final queries that work great:

qryMaxDates=
Code Tags Added by UG
Please use Code Tags when posting VBA Code
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Code:
SELECT Max(Orders.OrderDate) AS MaxO, CustomerID
FROM Orders
GROUP BY Orders.CustomerID;

SELECT Orders.*
FROM Orders INNER JOIN qryMaxDates ON (Orders.OrderDate = qryMaxDates.MaxO) AND (Orders.CustomerID = qryMaxDates.CustomerID);

Today's combined query that I get an error in:
Syntax error in join operation.

Code:
SELECT Orders.*
FROM Orders INNER JOIN Orders.OrderDate ON t2.MaxO And Orders.CustomerID ON t2.CustomerID
(
SELECT Max(t2.OrderDate) as MaxO, t2.CustomerID
FROM Orders t2
GROUP BY t2.CustomerID
)
 
Last edited by a moderator:

CJ_London

Super Moderator
Staff member
Local time
Today, 09:02
Joined
Feb 19, 2013
Messages
16,604
you need to look at Pauls example more closely - it should be more like

Code:
SELECT Orders.*
FROM Orders INNER JOIN
(
SELECT Max(tOrderDate) as MaxO, CustomerID
FROM Orders
GROUP BY CustomerID
)  t2
 ON Orders.OrderDate=t2.MaxO And Orders.CustomerID = t2.CustomerID
 

HardWorking

New member
Local time
Today, 04:02
Joined
Apr 13, 2020
Messages
8
Thank you for the correction CJ. You are right I should have gotten much closer with my query from looking at Paul's reply. Thanks for the help.

Hey I also got a note to use tags when using VBA code. I do not know what that means and I was not using vba code. I wrote my comments in notepad++ before pasting them in the textbox. I am sorry of I am doing something wrong. Can you explain the tags?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:02
Joined
Feb 19, 2013
Messages
16,604
re code tags the link is a bit out of date - instead of the # button, click on the 3 dot button in the ribbon, select </>code, then post your code in the newly opened window
 

Users who are viewing this thread

Top Bottom