What's up all? I have a query question that I just can't seem to figure out... I have two tables that I'm trying to join in my database.. This is the table layout..
Person Table
-------
personID
firstName
lastName
.
.
Phone Table
--------
personID
typeCode(1 for home, 2 for work)
dialNumber
extension
Basically I want to join the person table with the Phone table and get personID, and both home and work numbers in one line. I have the basic SQL statement to do this, but I've come across some problems...
Here is my statment so far..
SELECT Person.personID, Phone.dialNumber, Phone_1.dialNumber
FROM (Phone RIGHT JOIN Person ON Phone.personID = Person.personID) LEFT JOIN Phone AS Phone_1 ON Person.personID = Phone_1.personID WHERE (((Phone.typeCode)=1) AND ((Phone_1.typeCode)=2));
The problem is that I only get records that have 2 entries, one with a typeCode of 1 and one with a typeCode of 2. If a person doesn't have an both entries, then they don't show up in the results. I want to see these people, just assigning null to the missing value. For instance if a person had a home phone entry and no work phone entry then the record would return personID, homePhone, and NULL. If anyone can help me out here, I'd greatly appreciate it..
Doug
Person Table
-------
personID
firstName
lastName
.
.
Phone Table
--------
personID
typeCode(1 for home, 2 for work)
dialNumber
extension
Basically I want to join the person table with the Phone table and get personID, and both home and work numbers in one line. I have the basic SQL statement to do this, but I've come across some problems...
Here is my statment so far..
SELECT Person.personID, Phone.dialNumber, Phone_1.dialNumber
FROM (Phone RIGHT JOIN Person ON Phone.personID = Person.personID) LEFT JOIN Phone AS Phone_1 ON Person.personID = Phone_1.personID WHERE (((Phone.typeCode)=1) AND ((Phone_1.typeCode)=2));
The problem is that I only get records that have 2 entries, one with a typeCode of 1 and one with a typeCode of 2. If a person doesn't have an both entries, then they don't show up in the results. I want to see these people, just assigning null to the missing value. For instance if a person had a home phone entry and no work phone entry then the record would return personID, homePhone, and NULL. If anyone can help me out here, I'd greatly appreciate it..
Doug