|
Left outer join problem
I have the following query:
select co.contact_id, mobilephone.PHONENR_ID, mobilephone.PHONETYPE_ENUMID
from contact co ,
contactphonenr mobilecoph left join phonenr mobilephone on
mobilephone.phonenr_id = mobilecoph.phonenr_id and mobilephone.phonetype_enumid = 4
where co.CONTACT_ID = 200057 and co.CONTACT_ID = mobilecoph.contact_id
which applies to three tables: contact, phonenr and contactphonenr which is a link table between contact
and phonenr. The phonenr can be of three types: mobile, fax or main. I want the contact with the mobile
phonenr phoneid or if not present with an empty phoneid.
This query works more or less, but if the contact has a fax and main phonenr, but no mobile phonenr
the result is two records without a phoneid in stead of one.
Something simular happens when I try to select the fax for this contact, I receive a record with the fax and
an empty record.
Can anyone help me? And tell me why I receive two records in stead of one.
|