Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Const

select

Prisma Client's select option defines the scalar fields and relation fields included in a query result. It narrows both the returned payload and its generated TypeScript shape.

How it works

Use select inside a Prisma Client query to define the fields returned for a model. Set scalar fields to true, and use nested select objects to control which fields are returned from relations; the resulting TypeScript type reflects the selected shape.

Syntax

select: {
  fieldName: true,
  relationName: {
    select: {
      relatedField: true,
    },
  },
}

Parameters

NameTypeDescription
selectXOR<ModelSelect, null>An object whose boolean field entries and nested relation selections specify which properties Prisma Client returns.

Returns

A Prisma Client result containing only the selected scalar fields and selected relation fields, with the corresponding generated result type.

Key points

  • Use select as a field allowlist when the query needs only part of a model's scalar data.
  • A nested selection lets a query return a relation while limiting that relation to only the necessary fields.
  • Set each requested scalar property to true inside the selection object.
  • The default result includes model scalars but does not automatically load relations.

Common mistakes

  • Without a projection option, scalar fields are returned by default, so sensitive or unnecessary fields may be included.

Example: Select a focused result shape

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

const user = await prisma.user.findFirst({
  select: {
    email: true,
    name: true,
    posts: {
      select: {
        title: true,
        published: true,
      },
    },
  },
});

console.log(user);
await prisma.$disconnect();

Returns only the selected user fields and the selected fields from each related post.

When to use it

Create a minimal response payload

An API endpoint should expose only approved user properties rather than the complete model.

Reduce query result size

A list view needs a few columns from each record and no full relation objects.

Shape nested relation data

A detail view needs a relation but only selected fields from that relation.

Interview questions

QWhat does Prisma Client's select option do?

select specifies which properties Prisma Client includes in the returned object. A scalar field is enabled with true, and relations can contain nested selection objects.

Follow-up: How would you select a user's email and only each post's title? Use a top-level select for email and a nested posts.select containing title: true.

QWhat is returned when no select option is supplied?

By default, Prisma Client returns all scalar fields and no relations. Adding select narrows the result to the fields explicitly requested, which makes the payload and inferred result shape more intentional.

Follow-up: What happens if a relation is not selected? It is excluded from the returned result unless it is selected through a nested selection.

QCan select and include be combined?

select and include cannot be used together at the same query level. To return selected root fields and selected relation fields, use one top-level select and put another select inside the relation.

Follow-up: Can select appear inside include? Yes, a nested select can focus the fields of an included relation, but the root query must not combine select and include at the same level.

  • include
  • omit
  • nested select
  • Prisma Client queries

Source: Select fields (Prisma ORM v7). Checked 2026-10-16.