`count()` support distinct
See original GitHub issueProblem
I have bumped into a few cases where I need to do a ‘where’ filter and get records that are ‘distinct’, to add pagination I need to do a count query also with a ‘distinct’ option on ‘count()’, based on the documentation and experience, I can’t use distinct on a count()
export type FindManyUserArgs = {
where?: UserWhereInput | null
orderBy?: Enumerable<UserOrderByInput> | null
skip?: number | null
after?: UserWhereUniqueInput | null
before?: UserWhereUniqueInput | null
first?: number | null
last?: number | null
}
Suggested solution
Can we update count() to support distinct as well? so it would accept the object similar to findMany()
export type FindManyUserArgs = {
select?: UserSelect | null
include?: UserInclude | null
where?: UserWhereInput | null
orderBy?: Enumerable<UserOrderByInput> | null
cursor?: UserWhereUniqueInput | null
take?: number | null
skip?: number | null
distinct?: Enumerable<UserDistinctFieldEnum>
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:78
- Comments:25 (1 by maintainers)
Top Results From Across the Web
SQL COUNT() with DISTINCT - w3resource
SQL COUNT() function with DISTINCT clause eliminates the repetitive appearance of the same data. The DISTINCT can come only once in a given ......
Read more >Count unique values among duplicates - Microsoft Support
Let's say you want to find out how many unique values exist in a range that contains duplicate values. For example, if a...
Read more >Overview of the SQL Count Distinct Function - SQLShack
COUNT. Count(*). Count(Distinct) ; It returns the total number of rows after satisfying conditions specified in the where clause. It returns the ...
Read more >How to Count Distinct Values in SQL - LearnSQL.com
To count the number of different values that are stored in a given column, you simply need to designate the column you pass...
Read more >Count Distinct and Window Functions - Simple Talk
Count Distinct is not supported by window partitioning, we need to find a different way to achieve the same result.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would really love to see this feature added.
For folks who need this, here’s my workaround until it’s supported: