SQL LEFT JOIN

Keeps every row from the LEFT table no matter what — filling in NULL for any right-side columns that have no match.

What & Why

LEFT JOIN (also written LEFT OUTER JOIN) keeps every row from the left table, regardless of whether a match exists on the right. When there's no match, the right table's columns simply show up as NULL instead of the row disappearing.

See How It Works

BUSINESS QUESTION

Product wants feedback counts beside every feature, including features that have received no feedback.

idnamedescriptionteamreleased_atdeprecated_at
1Activation ChecklistGuides new users through setupgrowth2024-01-20NULL
2CSV ExportExports report dataplatform2024-02-14NULL
3Invite NudgesPrompts workspace collaborationgrowth2024-03-05NULL
4Legacy DashboardOriginal reporting surfaceanalytics2023-08-102024-06-01
iduser_idfeature_idratingnps_scorecommentcreated_at
1101159Clear and useful2024-01-25 12:15:00+00
210224NULLExport worked well2024-02-20 15:40:00+00
3103147Helpful setup flow2024-03-18 09:05:00+00
410433NULLNeeds clearer timing2024-04-08 17:30:00+00
Trace the relationship row by row1× speed
product.features
idname
1Activation Checklist
2CSV Export
3Invite Nudges
4Legacy Dashboard
COUNT MATCHES
product.feedback
idfeature_idratingcreated_at
1152024-01-25 12:15:00+00
2242024-02-20 15:40:00+00
3142024-03-18 09:05:00+00
4332024-04-08 17:30:00+00
Result set · 1 rows
namefeedback_count
Activation Checklist2

Activation Checklist contributes its exact feedback count.

EXAMPLE QUERY
SELECT
  f.name,
  COUNT(fe.id) AS feedback_count
FROM product.features f
LEFT JOIN product.feedback fe ON fe.feature_id = f.id
GROUP BY f.id, f.name
ORDER BY feedback_count ASC, f.name;
Intermediate business practice

Sign up free to try it on a real business scenario