Re: Please advice on a query

From: Efraín Déctor <efraindector(at)motumweb(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Please advice on a query
Date: 2017-11-14 17:19:30
Message-ID: 30a9085d-9423-33ed-5013-6d73001b7628@motumweb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello.

You could use a window function:
https://www.postgresql.org/docs/current/static/functions-window.html

El 14/11/2017 a las 11:04 a. m., JORGE MALDONADO escribió:
> I have a table with a date field and I need to get all of the records
> with the most recent date.
> For example, if I have the following records, I need to get all of
> them with date 2017-11-09 only. which represent the most recent.
>
> What would be a good approach?
>
> 2017-01-01
> 2017-01-01
> 2017-10-15
> 2017-10-15
> 2017-10-15
> 2017-11-09
> 2017-11-09
> 2017-11-09
> 2017-11-09
>
> I thought about issuing a SELECT DISTINCT to get one record for each
> date, ORDER BY date DESC and then LIMIT 1 so I finally get the most
> recent date and use it in the WHERE clause. But this seems to me a bit
> complex.
>
> Respectfully,
> Jorge Maldonado

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Peter Geoghegan 2017-11-14 18:10:09 Re: Strange problem with autovacuum
Previous Message Efraín Déctor 2017-11-14 17:11:13 Re: Strange problem with autovacuum