Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL: Multiple joins on multiple tables where some column values are not mandatory

I am trying to join multiple tables where the values in columns e.Email, e.Phone are voluntary. I would like to select all rows even if e.Email, e.Phone contain empty values.
Currently, I am only able to select rows where e.Email, e.Phone values are present.


SELECT a.ID_1
 
,b.Tier
 
,e.Email
 
,e.Phone



FROM CustomerActivity a 

JOIN CustomerSummary b

ON a.ID_1 = b.ID_1

JOIN DimensionCustomer c

ON b.ID_1 = c.ID_1

JOIN LegacyCustomerMapping d

ON c.ID_2 = d.ID_2

JOIN LegacyCustomerContactData e

d.ID_3 = e.ID_3

Many thanks for any kind of advice!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I would recommend using left join instead of join in your query. That should get the results you are looking for.

Image from: https://www.w3schools.com/sql/sql_join.asp

Image taken from https://www.w3schools.com/sql/sql_join.asp

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading