Skip to content
Skills Library
Data & analytics · Learning & explanation

sql-joins

/sql-joins

Choose and write the right join so rows are neither lost nor multiplied, and know why a result set grew. Use when combining tables and the row count or the null columns look wrong.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Choose and write the right join so rows are neither lost nor multiplied, and know why a result set grew. Use when combining tables and the row count or the null columns look wrong.

Original author description

Choose and write the right join so rows are neither lost nor multiplied, and know why a result set grew. Use when combining tables and the row count or the null columns look wrong.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 43 lines, 346 words
SKILL.md preview
---
name: sql-joins
description: Choose and write the right join so rows are neither lost nor multiplied, and know why a result set grew. Use when combining tables and the row count or the null columns look wrong.
---

# SQL joins

Almost every wrong query result traces to a join: an inner join that
silently dropped the rows you cared about, or a join on a non-unique key
that quietly multiplied them. Joins are simple to write and easy to get
subtly wrong, which is why the row count is the first thing to check.

## Method

1. **State the grain before writing the join.** One row per what?
   Per order, per order line, per customer. Knowing the intended grain is
   what lets you see immediately that a result is wrong.
2. **Pick the join by what should survive.** Inner keeps only matches,
   left keeps every row of the left side, and full keeps both. Choosing
   inner when you meant left is the most common cause of quietly missing
   rows.
3. **Check the key's uniqueness on both sides.** Joining on a column
   that repeats on the right multiplies rows. If the right side is not
   unique per key, aggregate it first or accept the fan-out knowingly.
4. **Put filters in the right place.** A condition on the right table in
   the WHERE clause turns a left join into an inner join, because null
   fails the comparison. Filters that must not do that belong in the ON
   clause.
5. **Count before and after.** Compare the row count to the left table's
   count when you expected preservation. A join that changed the count
   unexpectedly is a bug you found early rather than a wrong number you
   shipped.
6. **Use an anti-join to find what is missing.** A left join filtered to
   null on the right, or NOT EXISTS, answers which rows have no match,
   which is usually clearer than NOT IN and safe with nulls (see
   null-semantics).

## Boundaries

- Joins combine rows; they do not fix a schema where the relationship is
  ambiguous (see database-normalization).
- Join performance depends on indexes and plan choice, which is a
  separate concern from correctness (see indexing-strategy,
  query-plan-reading).
- Cross joins are occasionally intended, so an exploding row count is
  only a bug relative to the grain you declared.

Versions

The database has no other skills named sql-joins.

Database snapshot: 13.11.2026 · package version 9a0a764219e0 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100spatial-joins-and-keys
    Getting attribute joins and spatial joins right, covering key types, leading-zero padding (CSJ, county FIPS, ZIP), case and whitespace, null keys, one-to-many row blowups, intersects vs within vs contains, boundary effects and reporting the match rate honestly. Use it when asked…
  • 90null-semantics
    Reason about SQL nulls in comparisons, aggregates, joins, and uniqueness so absent values stop producing wrong or missing rows. Use when a query silently drops rows or a NOT IN returns nothing.
  • 90investigate
    Investigate a data quality problem (a metric that dropped or spiked, duplicate rows, a join returning the wrong row count, a stale table, a failing dbt test) using the dqsleuth MCP tools. Use when the user reports a symptom in their data and wants the root cause, not just a test result.
  • 100reproducible-analysis
    Profile a dataset and validate a result before reporting it. Use when data first arrives, when a join or filter changes the row count, or when a finding looks surprising enough to be a bug.
  • 90sql-set-operations
    Combine result sets with UNION, INTERSECT, and EXCEPT, and know when a join or an exists clause is the better tool. Use when merging or comparing two query results rather than two tables.
  • 100sql
    Write, run, and explain SQL queries, and do quick local analysis of CSV/SQLite data with the sqlite3 CLI. Use when users want a SQL query written or fixed, want to query a .db/.sqlite file, or want to analyze a CSV with SQL (joins, group by, window functions). Triggers on…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.