In SQL you can use a DISTINCT to select only unique column values from rows that contain values that are repeated. There is also a GROUP BY in SQL to essentially do the same thing, but has unique benefits that allow you to do things similar to using rollups in Glide.
The problem comes up quite often where people want to display unique rows in a collection that contains several duplicates. I think it would be beneficial if we had a Distinct/Unique option in the collection configuration where we can specify any number of columns to be considered as a unique key.
For example let’s say we have a table like this:
Name | Category | Amount | |
---|---|---|---|
Jeff | Type 1 | 50 | |
Jeff | Type 1 | 51 | |
Jeff | Type 2 | 150 | |
Jeff | Type 2 | 151 | |
Jeff | Type 3 | 250 | |
Peter | Type 1 | 50 | |
Peter | Type 1 | 51 | |
Peter | Type 2 | 150 | |
Peter | Type 2 | 151 | |
Peter | Type 3 | 250 |
Ultimately I want the collection to only display Distinct/Unique rows like this:
Name | Category | Amount | |
---|---|---|---|
Jeff | Type 1 | 50 | |
Jeff | Type 2 | 150 | |
Jeff | Type 3 | 250 | |
Peter | Type 1 | 50 | |
Peter | Type 2 | 150 | |
Peter | Type 3 | 250 |
What I’m thinking is to have a Distinct/Unique configuration option in the collection settings where I could specify both Name and Category (and any other number of columns) as the columns to be used to define a row as unique.
Now I’m sure some of you might already see a problem…if we are essentially filtering out duplicates, then which Amount do we display? I think 99% of the time, that wouldn’t be an issue, but someone will run into it eventually. I don’t have a good answer for that, but I’m thinking we would always display the first distinct row and ignore the rest. The collection sorting could control which row is considered the first one in a unique grouping, or maybe we could have something like how a Single Value column works where you can specify first or last row. I’m open to any thoughts to improve the idea.