Important Concept: EXISTS vs JOIN

Understanding when to use EXISTS and when to use JOIN is very important in SQL.

1. Use EXISTS when you only care about “Existence” (at least once)

WHERE EXISTS (
    SELECT 1 
    FROM FactSurveyResponse SR 
    WHERE SR.CustomerKey = C.CustomerKey
)

Result: Each customer appears only once, even if they have many survey responses.

2. Use JOIN when you need data from the other table

LEFT JOIN FactSurveyResponse SR 
    ON C.CustomerKey = SR.CustomerKey
WHERE SR.CustomerKey IS NOT NULL

Result: Can return duplicate rows if a customer responded to multiple surveys.

Key Takeaway

  • EXISTS / NOT EXISTS → Best for checking “Does this exist at least once?”
  • JOIN → Best when you want to bring columns from another table
  • JOIN can create duplicate rows if there are multiple matches

This concept appears frequently in healthcare analytics — for example:

  • Members who had at least one denied claim
  • Products that were never sold
  • Patients who have specific conditions
Scroll to Top