using 2 tables:
Table 1 is a list of unique ID's as CID
Table 2 is a list of Home and Mailing Addresses linked via CID and aType = HOME | MAIL
All CID's must have a Home Address but can optionally have a Mail Address ... records aren't allowed to be deleted or changed ... any changes will result in new records being generated ... assigned ANID (Autonumber Primary Index) to table 2 and HANID which should always match the CID's current home address
The subQuery below has an issue with the value of [highlight #EF2929]T1.cid[/highlight] not being available for the where clauses in subqueries TMX1 and TMX2 ... the query will run if I remove these subqueries but results in too many rows.
Table 1 is a list of unique ID's as CID
Table 2 is a list of Home and Mailing Addresses linked via CID and aType = HOME | MAIL
All CID's must have a Home Address but can optionally have a Mail Address ... records aren't allowed to be deleted or changed ... any changes will result in new records being generated ... assigned ANID (Autonumber Primary Index) to table 2 and HANID which should always match the CID's current home address
Code:
Table 1
CID
01
02
03
Table 2
ANID HANID CID aType Address
1 1 01 Home 123 Abc St Somewhere Land
2 2 02 Mail PO Box 124 Somewhere Land
3 3 03 Home 452 Xyz Ave Somewhere Else Land
4 3 03 Mail PO Box 125 Somewhere Else Land
5 5 01 Home 245 Jkl Ave Some Other Land
The subQuery below has an issue with the value of [highlight #EF2929]T1.cid[/highlight] not being available for the where clauses in subqueries TMX1 and TMX2 ... the query will run if I remove these subqueries but results in too many rows.
Code:
Select T1.cid, Home.aType, Home,Address, Mail.aType, Mail.Address
From ((Table1 As T1
Left Join [
Select Table2.cid, Table2.aType, Table2.Address
From Table2
Where Table2.aType = "Home"
And
Table2.hanid = (Select Max(Table2.hanid)
From Table2 As TMX1
Where TMX1.cid = [highlight #EF2929]T1.cid[/highlight])]. As Home
ON T1.cid = Home.cid)
Left Join [
Select Table2.cid, Table2.aType, Table2.Address
From Table2
Where Table2.aType = "Mail"
And
Table2.hanid = (Select Max(Table2.hanid)
From Table2 As TMX2
Where TMX2.cid = [highlight #EF2929]T1.cid[/highlight])]. As Mail
ON T1.cid = Mail.cid)