Hello! Postgres lets us omit columns from a GROUP BY clause if they are
functionally dependent on a grouped key, which is a nice quality-of-life
feature. I'm wondering if a similar relaxation could be permitted for
the SELECT DISTINCT list?
I have a query where I want to find the most recent few i
On Thu, Sep 12, 2024 at 11:13 PM wrote:
>
> What about using DISTINCT ON () ?
> SELECT DISTINCT ON (items.id) items.*
> FROM items
> JOIN parts ON items.id = parts.item_id
> WHERE part_id % 3 = 0
> ORDER BY items.id,items.create_time DESC
> LIMIT 5;
>
> This gives me this
Thanks both for your suggestions so far.
On Fri, Sep 13, 2024 at 8:43 AM David G. Johnston
wrote:
>
> On Friday, September 13, 2024, Willow Chargin wrote:
>>
>> In reality I really do want the ID columns of the
>> *most recent* items.
>
>
> Use a window function
On Sun, Sep 15, 2024 at 4:23 AM Alban Hertroys wrote:
>
> > On 15 Sep 2024, at 11:07, Dan Kortschak wrote:
> >
> > I have come to hopefully my last stumbling point.
> >
> > I am unable to see a way to express something like this SQLite syntax
> >
> > select json_group_array(json_replace(value,
>