Hi I have a problem trying to build a query where I have 2 different foreign keys pointing to one primary key, Im not sure if a CTE in SQL would be the way forward to deal with this as my SQL isnt that great:
tbl_site:
SiteKey (P)
SiteDescription
AddressKey (F)
tbl_school:
SchoolKey (P)
SchoolName
SiteKey
AddressKey (F)
tbl_Address:
AddressKey (P)
Add1
.
.
Add6
PostCode
I am trying to return a query that shows:
SiteKey (All records)
SiteName
SchoolKey (schools are joined to sites on a zero to many relationship)
SchoolName
Add1
.
.
Add6
PostCode
My Issue is that where there is a school against a site the address is held at school level, but where there is no school the address is held at site level. I can only ever seem to get one level of address returned no matter which way I try and write the query. All other ideas I have tried all lead to a duplication of the 6 address and postcode columns.
Any have any ideas how to get round this?