I have two tables (Contact_Table and Order_Table) and I have current using a query like this
SELECT a.CustID, a.EmailAddress, a.Contact, a.Country, b.OrderID
FROM a.Contact_Table a
INNER JOIN b.Order_Table b
ON b.CustID = a.CustID
Contact_Table
CustID | EmailAddress | Contact | Country |
---|---|---|---|
9909 | abc1@email1.com | Maria Anders | Germany |
7636 | abc2@email2.com | Francisco Chang | Mexico |
1927 | Roland Mendel | Austria |
Order_Table
CustID | OrderID |
---|---|
9909 | 123 |
7636 | 1234 |
But the issue is, I do not have email address value for all contacts in Contact_Table
I have a 3rd table - Contact_Table_HistoricalData
Contact_Table_HistoricalData
CustID | EmailAddress | Contact |
---|---|---|
9909 | abc1@email1.com | Maria Anders |
7636 | abc2@email2.com | Francisco Chang |
1927 | abc3@email3.com | Roland Mendel |
How can I use this Contact_Table_HistoricalData table in my query for records where email address is NOT available then get email address value from Contact_Table_HistoricalData table?