---
source: https://iinventedlight.com/library/notes/django-select-related.md
title: "select_related joins foreign keys in one query; prefetch_related uses extra queries"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); BSD-3-Clause (django/django (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Django docs, QuerySet API reference (select_related and prefetch_related), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors; django/django (GitHub), querysets.txt (Django source docs), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: Django select_related and prefetch_related"
tags: [django, select_related, prefetch_related, queryset, n-plus-one]
client: Librarian
sources:
  - id: S1
    title: "QuerySet API reference (select_related and prefetch_related)"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/6.1/ref/models/querysets/
    accessed: 2026-11-17
    license: "BSD-3-Clause"
  - id: S2
    title: "querysets.txt (Django source docs)"
    publisher: django/django (GitHub)
    url: https://github.com/django/django/blob/stable/6.1.x/docs/ref/models/querysets.txt
    accessed: 2026-11-17
    license: "BSD-3-Clause"
---
# select_related joins foreign keys in one query; prefetch_related uses extra queries
**Answer:** `select_related()` returns a `QuerySet` that joins named foreign-key relationships and selects the extra related objects when that query runs. Used this way, it can boost performance by fetching data early, instead of triggering on-demand loading. `prefetch_related` does a separate lookup for each relationship and does the joining in Python.

## When to use which

Because a join across a many-valued relation would explode the result set, `select_related` is limited to foreign key and one-to-one. `prefetch_related` can also follow many-to-many and many-to-one relations. You can follow foreign keys with a chain such as `author__hometown`. Pass `None` to clear related fields added by earlier `select_related` calls.

Prefetching helps when you already know you will touch related objects later, so you can avoid a query per object. Those extra `prefetch_related()` queries run after the `QuerySet` starts evaluating and after the primary query has finished.

## See also

- [django-querysets](https://iinventedlight.com/library/notes/django-querysets/)
- [django-models](https://iinventedlight.com/library/notes/django-models/)
- [django-management-commands](https://iinventedlight.com/library/notes/django-management-commands/)
- [django-signals](https://iinventedlight.com/library/notes/django-signals/)

## Claims

- id: C1
  claim: select_related joins named foreign-key relationships in the same query.
  source: S1
  evidence: "join in the named foreign-key relationships"

- id: C2
  claim: select_related is limited to foreign key and one-to-one relations.
  source: S1
  evidence: "limited to single-valued relationships"

- id: C3
  claim: prefetch_related does a separate lookup for each relationship.
  source: S2
  evidence: "does a separate lookup for each relationship"

- id: C4
  claim: prefetch_related can fetch many-to-many and many-to-one relations.
  source: S2
  evidence: "many-to-many, many-to-one"

## Sources

- [S1] QuerySet API reference (select_related and prefetch_related). Django docs. https://docs.djangoproject.com/en/6.1/ref/models/querysets/ . License: BSD-3-Clause. Accessed 2026-11-17.

- [S2] querysets.txt (Django source docs). django/django (GitHub). https://github.com/django/django/blob/stable/6.1.x/docs/ref/models/querysets.txt . License: BSD-3-Clause. Accessed 2026-11-17.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, QuerySet API reference (select_related and prefetch_related), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors; django/django (GitHub), querysets.txt (Django source docs), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
