Hi there, How is it possible to query the followin...
# orm-help
l
Hi there, How is it possible to query the following with prisma: i want to query a list of elements, and wanna add a uniqueness for a specific attribute for the results i recieve (so that there are no two results with the same value in the '_uniqueness-key',_ although there are multiple with the same value for that key in the database_)_. Example Schema:
Copy code
model Entry {
  id        String   @id
  category  String
}
Having the Entry model filled with data:
Copy code
id: '0', category: 'A'
id: '1', category: 'A'
id: '2', category: 'B'
id: '3', category: 'C'
id: '4', category: 'B'
executing the query for I would like to recieve all queries, where the value of category hasn't been fetched before into the resulting data:
Copy code
id: '0', category: 'A'
id: '2', category: 'B'
id: '3', category: 'C'
Any ideas?
r
@Luis Kuper 👋 I cannot think of anything other than
group by
and then fetching the first value from that. In a raw query, I think
partition
should work if you’re using Postgres.
l
Hi @Ryan thanks for the fast support. Can groupBy be applied to joined keys aswell? (e.g. Group by the category of a 1:1 related model)
r
I don’t think so. Just the keys of the same model.
l
Just out of curiosity: What about distinct, is there a reason you didn't suggest that?
r
Yeah that should work as well.
👍 1