X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0F0DFD1E831 for ; Mon, 19 Jan 2004 04:55:20 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 15441-10 for ; Mon, 19 Jan 2004 00:54:49 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id EBCDBD1E82A for ; Mon, 19 Jan 2004 00:54:48 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id i0J4skpH020560; Sun, 18 Jan 2004 23:54:46 -0500 (EST) To: "OizOne" Cc: pgsql-sql@postgresql.org Subject: Re: help with limiting query results In-reply-to: <20040113193312.05BDAEB4942@gw02.mail.saunalahti.fi> References: <20040113193312.05BDAEB4942@gw02.mail.saunalahti.fi> Comments: In-reply-to "OizOne" message dated "Tue, 13 Jan 2004 21:34:08 +0200" Date: Sun, 18 Jan 2004 23:54:46 -0500 Message-ID: <20559.1074488086@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/160 X-Sequence-Number: 16553 "OizOne" writes: > I would need to create a query that selects each hostname only once with > username that has the latest timestamp in the logontime column. SELECT DISTINCT ON is a convenient way to do this. See the "weather reports" example in the SELECT reference page for a similar case. regards, tom lane