Now that you have joined two tables together, there is some profiling, analysis, and critical thinking required to ensure your result will accurately reflect your desired output. There are numerous issues that can arise where your results will mis-represent your desired results. In theory, you wanted to understand Leads that are converted. An inner join will ensure only records with L.”ConvertedAccountId” and A.”Id” that match are returned.
What about leads without ConvertedAccountId record?
Leads that are missing a field ConvertedAccountId are not returned.
What about joining 2 tables containing fields with NULL values?
Snowflake (or any SQL database) will not create a Cartesian product due to NULL values in the join conditions. Instead, it will ignore rows in LEAD where ConvertedAccountId is NULL, because those NULL values won’t find any matching Id in the ACCOUNT table (since NULL does not equal anything, not even another NULL). The result set will only include leads that have a non-null ConvertedAccountId that matches an Id in the ACCOUNT table.
How can you determine how many Leads are missing from Accounts?
The simple way to make this determination is to check for the existence of a foreign key:
SELECT COUNT(*) AS " Leads Count" FROM LEAD WHERE "ConvertedAccountId" IS NULL;
This works for simple examples. Over time as you learn and find better ways to solve problems you will likely accumulate your own library of SQL scripts to help you quickly solve problems. When I profile and determine record counts, I use SQL like this:
How can you determine how many Accounts are missing from the Leads Table?