Advanced Querying & Filtering in Prisma
From the Prisma ORM cheat sheet · Prisma Client Queries · verified Jul 2026
Advanced Querying & Filtering
Complex queries with filtering, sorting, pagination, and aggregations
typescript
// Complex filtering
const posts = await prisma.post.findMany({
where: {
OR: [
{ title: { contains: 'prisma' } },
{ content: { contains: 'database' } }
],
AND: [
{ status: 'PUBLISHED' },
{ author: { role: 'ADMIN' } }
],
tags: {
some: { name: { in: ['tech', 'tutorial'] } }
}
}
})
// Aggregations and grouping
const stats = await prisma.post.aggregate({
_count: { id: true },
_avg: { viewCount: true },
where: { status: 'PUBLISHED' }
})💡 Combine multiple filters with AND, OR, NOT
⚡ Use cursor-based pagination for large datasets
📌 Aggregate functions: count, sum, avg, min, max
✅ Use distinct to remove duplicates