Combine Firms, Funds, and Investments Data
Beginner Mode

Scenario

You work for a private equity data platform and have been given three tables containing PE firm details, fund information, and investment records. Not every firm has a fund, not every fund belongs to a firm, and not every investment is tied to a fund.

Task

Write a Snowflake SQL query that:

  1. Performs a FULL OUTER JOIN between {{ ref("firms") }} and {{ ref("funds") }} on firm_id
  2. Performs a FULL OUTER JOIN between the result and {{ ref("investments") }} on fund_id
  3. Uses COALESCE to produce a single firm_id (from firms or funds) and a single fund_id (from funds or investments)
  4. Selects all 13 columns listed in the output schema
  5. Filters out any rows where every column is NULL

Schema

firms

Column Type Description
firm_id Integer Unique identifier of the PE firm
firm_name String Name of the PE firm
founded_year Integer Year the PE firm was founded
location String Headquarters location of the PE firm

funds

Column Type Description
fund_id Integer Unique identifier of the PE fund
firm_id Integer Identifier linking the fund to a firm
fund_name String Name of the PE fund
fund_size Integer Size of the fund in millions of dollars
fund_start_year Integer Year the fund was started
fund_end_year Integer Year the fund ended (or is expected to end)

investments

Column Type Description
investment_id Integer Unique identifier of the investment
fund_id Integer Identifier linking the investment to a fund
company_name String Name of the company receiving the investment
investment_amount Integer Amount invested in millions of dollars
investment_date String Date of the investment

Expected Output Schema

Column Type Description
investment_id Integer Unique identifier of the investment
fund_id Integer Identifier of the fund (from either table)
firm_id Integer Identifier of the firm (from either table)
firm_name String Name of the PE firm
founded_year Integer Year the PE firm was founded
location String Headquarters location of the PE firm
fund_name String Name of the PE fund
fund_size Integer Size of the fund in millions of dollars
fund_start_year Integer Year the fund was started
fund_end_year Integer Year the fund ended (or is expected to end)
company_name String Name of the company receiving the investment
investment_amount Integer Amount invested in millions of dollars
investment_date String Date of the investment

Example

firms:

firm_id firm_name founded_year location
1 Apex Capital 2008 Chicago
2 Bridge Partners 2012 Boston
3 Crest Ventures 2016 Denver

funds:

fund_id firm_id fund_name fund_size fund_start_year fund_end_year
10 1 Growth I 200 2009 2014
11 2 Value I 150 2013 2018
12 99 Orphan Fund 80 2017 2022

investments:

investment_id fund_id company_name investment_amount investment_date
101 10 TechStart 25 2010-03-15
102 11 GreenEnergy 30 2014-09-05
103 88 SoloVenture 15 2020-11-30

Expected Output:

investment_id fund_id firm_id firm_name founded_year location fund_name fund_size fund_start_year fund_end_year company_name investment_amount investment_date
101 10 1 Apex Capital 2008 Chicago Growth I 200 2009 2014 TechStart 25 2010-03-15
102 11 2 Bridge Partners 2012 Boston Value I 150 2013 2018 GreenEnergy 30 2014-09-05
NULL 12 99 NULL NULL NULL Orphan Fund 80 2017 2022 NULL NULL NULL
NULL NULL 3 Crest Ventures 2016 Denver NULL NULL NULL NULL NULL NULL NULL
103 88 NULL NULL NULL NULL NULL NULL NULL NULL SoloVenture 15 2020-11-30

Note: Crest Ventures (firm_id=3) has no associated funds. Orphan Fund (firm_id=99) has no matching firm and no investments. SoloVenture (fund_id=88) has no matching fund. All three rows are preserved because they are not entirely NULL. Any row where every column is NULL would be excluded.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →