C
Corey Burnett
I have the following tables:
Address, LState, Country, Contact
Every Contact has one or more Addresses. Each Address may
or may not have a State or Country. I want to write a
query that will pull Contact information as well as
address information. I want the query to pull State and
Country information if it is there but return NULL if not.
If I write the query without joining to the Contact table
it works fine as follows:
SELECT Address.AddressID, LState.StateName,
Country.CountryName FROM (Address LEFT JOIN LState ON
Address.StateID = LState.StateID) LEFT JOIN Country ON
Address.CountryID = Country.CountryID;
This returns the expected list of all AddressIDs with
State and Country information. Those records that do not
have associated values in the State and Country tables
have null values.
Now if I want to bring in some information about the
contact also the query changes to this:
SELECT Address.AddressID, LState.StateName,
Country.CountryName, Contact.FirstName, Contact.LastName
FROM Contact INNER JOIN ((Address LEFT JOIN LState ON
Address.StateID = LState.StateID) LEFT JOIN Country ON
Address.CountryID = Country.CountryID) ON
Contact.ContactID = Address.ContactID;
The query still runs but the problem is that when I add in
the Contact table to the query then all of a sudden the
StateName field is NULL for every record in the result
set! No matter how I rearrange the query it always omits
either the StateName or the CountryName field with NULL
values. We are using Access 2000. Any ideas?
Thanks,
Corey Burnett
Address, LState, Country, Contact
Every Contact has one or more Addresses. Each Address may
or may not have a State or Country. I want to write a
query that will pull Contact information as well as
address information. I want the query to pull State and
Country information if it is there but return NULL if not.
If I write the query without joining to the Contact table
it works fine as follows:
SELECT Address.AddressID, LState.StateName,
Country.CountryName FROM (Address LEFT JOIN LState ON
Address.StateID = LState.StateID) LEFT JOIN Country ON
Address.CountryID = Country.CountryID;
This returns the expected list of all AddressIDs with
State and Country information. Those records that do not
have associated values in the State and Country tables
have null values.
Now if I want to bring in some information about the
contact also the query changes to this:
SELECT Address.AddressID, LState.StateName,
Country.CountryName, Contact.FirstName, Contact.LastName
FROM Contact INNER JOIN ((Address LEFT JOIN LState ON
Address.StateID = LState.StateID) LEFT JOIN Country ON
Address.CountryID = Country.CountryID) ON
Contact.ContactID = Address.ContactID;
The query still runs but the problem is that when I add in
the Contact table to the query then all of a sudden the
StateName field is NULL for every record in the result
set! No matter how I rearrange the query it always omits
either the StateName or the CountryName field with NULL
values. We are using Access 2000. Any ideas?
Thanks,
Corey Burnett