Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMp05-004nuP-Jg for pgsql-general@arkaria.postgresql.org; Thu, 27 Jun 2024 13:17:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sMoz5-00AHjC-CU for pgsql-general@arkaria.postgresql.org; Thu, 27 Jun 2024 13:16:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMoz5-00AHj3-1T for pgsql-general@lists.postgresql.org; Thu, 27 Jun 2024 13:16:19 +0000 Received: from wolff.to ([98.103.208.27]) by magus.postgresql.org with smtp (Exim 4.94.2) (envelope-from ) id 1sMoz2-003pNs-9m for pgsql-general@lists.postgresql.org; Thu, 27 Jun 2024 13:16:18 +0000 Received: (qmail 3185 invoked by uid 500); 27 Jun 2024 13:06:29 -0000 Date: Thu, 27 Jun 2024 08:06:29 -0500 From: Bruno Wolff III To: Laurenz Albe Cc: Tom Lane , pgsql-general@lists.postgresql.org Subject: Re: Can any_value be used like first_value in an aggregate? Message-ID: <20240627130629.GA1433@wolff.to> Mail-Followup-To: Bruno Wolff III , Laurenz Albe , Tom Lane , pgsql-general@lists.postgresql.org References: <20240625164208.GA1043@wolff.to> <1337453.1719335325@sss.pgh.pa.us> <20240625191157.GA2861@wolff.to> <3998e51e47ce6b00c690cabfe4c60004ba42d8eb.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <3998e51e47ce6b00c690cabfe4c60004ba42d8eb.camel@cybertec.at> User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jun 26, 2024 at 09:50:59 +0200, Laurenz Albe wrote: >On Tue, 2024-06-25 at 14:11 -0500, Bruno Wolff III wrote: >> The actual >> use case is a set of tripplets returned from a query, where I want on >> row for each distinct value in the first column, paired with the value >> in the second column, for which the third column is the largest. The >> second and third columns are effectively dependent on each other, so there >> won't be any ambiguity. > >Try > > SELECT DISTINCT ON (first_column) > first_column, > second_column, > third_column > FROM the_table > ORDER BY first_column, third_column DESC; That approach worked for that part of the query. Thanks.