How can I nest two subqueries and two left joins at the same time? I currently have my query (query1) as below which works perfect.. But it involves connecting two outside queries which have to be updated separtely by data date.
I want to extend query1 by applying subquery (query2) out for practice and to also update everything in one script.
NOTE: Query is written in MS Access.
Any help is much appreciated!
SELECT DISTINCT 
Acct.AccountNumber
, Acct.ABCat AS Cat
, Acct.fName AS FirstName
, Acct.lName AS LastName
, Acct.Age AS Age
, o.Type, o.OFirstLoginDate
, o.OLastLoginDate
, m.Type
, m.LstDepDate AS LastDepDate
FROM 
table1 AS Acct 
LEFT JOIN 
        OB_table AS o 
        ON Acct.AccountNumber = o.AccountNumber
LEFT JOIN 
        MB_table AS m 
        ON Acct.AccountNumber = m.AccountNumber
WHERE 
Acct.Cat IN (9,12,16,17)
AND Acct.DataDate = 20200430 
AND Acct.Status = 'Open';
Query2 Using Subqueries and Left Join I get the error
Syntax error (missing operator) in query expression 'Acct.AccountNumber = o.AccountNumber    
LEFT JOIN 
(SELECT DISTINCT 
ParentAccount AS AccountNumber
,TYPE
,LstDepDate AS LastDepDate
FROM MBtable
WHERE ProcessDate = 20200430
SELECT DISTINCT 
Acct.AccountNumber
, Acct.ABCat AS Cat
, Acct.fName AS FirstName
, Acct.lName AS LastName
, Acct.Age AS Age
, o.Type, o.OFirstLoginDate
, o.OLastLoginDate
, m.Type
, m.LstDepDate AS LastDepDate
FROM 
table1 AS Acct 
LEFT JOIN 
(
SELECT DISTINCT 
Online.Account AS AccountNumber
, Online.TYPE
, Online.OBFLDate AS OFirstLoginDate
, Online.OBLLDate AS OLastLoginDate
FROM OBtable AS Online
WHERE Online.DataDate=20200430 
And Online.OBFLDate Is Not Null
)
AS o 
ON Acct.AccountNumber = o.AccountNumber
LEFT JOIN
(
SELECT DISTINCT 
ParentAccount AS AccountNumber
, TYPE
, LstDepDate AS LastDepDate
FROM MBtable
WHERE ProcessDate = 20200430 
AND FDate IS NOT NULL
ORDER BY LDate DESC
) 
AS m 
ON Acct.AccountNumber = m.AccountNumber
WHERE Acct.Cat IN (9,12,16,17)
 AND Acct.DataDate=20200430 
AND Acct.Status = 'Open';
 
    