New to SQL. Building my first contact manager project. Current schema can be seen below.
Issue:
- I'm working on a view that shows all contact types (phone, email, socials, address) for a given contact.
- I put together the following attempt, but it only returns results if the
contactGUIDis in every contact_type table.
--Problem: Only returns records if contactGUID is present in every contact_type table
SELECT
c.contGUID, c.contType,
i.indTitle, i.indFirstName, i.indMidName, i.indLastName,
e.emailAddress, e.emailDomain,
p.phnCountryCode, p.phnAreaCode, p.phnNumber,
s.socURL, s.socHandle,
a.addrCountry, a.addrCountryCode, a.addrCountrySubdivision, a.addrCountrySubName, a.addrSecondarySubdiv, a.addrMunicipality, a.addrMuniSubdivision, a.addrStreetNumber, a.addrStreetName, a.addrPostalCode, a.addrLatitude, a.addrLongitude
FROM
CONTACT c
JOIN INDIVIDUALS i
ON c.contGUID = i.indGUID
JOIN CONTACT_EMAIL ce
ON c.contGUID = ce.contactGUID
JOIN EMAILS e
ON ce.emailGUID = e.emailGUID
JOIN CONTACT_PHONE cp
ON c.contGUID = cp.contactGUID
JOIN PHONES p
ON cp.phnGUID = p.phnGUID
JOIN CONTACT_SOCIAL cs
ON c.contGUID = cs.contactGUID
JOIN SOCIALS s
ON cs.socGUID = s.socGUID
JOIN CONTACT_PHYS_ADDRESS cpa
ON c.contGUID = cpa.contactGUID
JOIN PHYS_ADDRESSES a
ON cpa.addrGUID = a.addrGUID
Question:
- How do I return all other contact types (email, social, address) if say,
CONTACT_PHONErecord is not present for a givencontactGUID?
