I'm trying to write a very straightforward query: I want to pull all accounts in a snowflake table, and flag accounts (True/False) that can be linked to a record in the opportunity table with "Startup" in the type field.
Here is a query that I thought would return what I am looking for:
SELECT
acc.id
, acc.id IN (
SELECT DISTINCT(opp.accountid)
FROM "OPPORTUNITY" opp
WHERE opp.type LIKE '%Startup%'
) AS startup
FROM "ACCOUNT" acc
The account table has ~100,000 distinct records and the subquery returns a list of only ~11,000 distinct account ids, yet the field aliased as 'startup' contains TRUE for each account. I've tried diagnosing why this returns all True with no luck. I also tried writing this same query using EXISTS with a correlated subquery and got the same results.
I was able to build a working query by essentially left joining the sub query after the FROM clause, but I would love to understand why the query above fails to evaluate correctly for each row.
Any help would be appreciated. Thanks!