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
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.
License: CC-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.
Cite this
iinventedlight. 2026. "select_related joins foreign keys in one query; prefetch_related uses extra queries." iinventedlight Library, iil:note:va9gn0qj, version of 2026-11-17. https://iinventedlight.com/library/notes/django-select-related/. License: CC-BY-4.0.
@misc{iil_note_va9gn0qj,
author = {{iinventedlight}},
title = {{select\_related joins foreign keys in one query; prefetch\_related uses extra queries}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/django-select-related/},
note = {Permanent ID iil:note:va9gn0qj. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-select-related.md.