Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6Zdo-000310-Th for pgsql-sql@arkaria.postgresql.org; Fri, 05 May 2017 09:35:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d6Zdn-0005ph-Iy for pgsql-sql@arkaria.postgresql.org; Fri, 05 May 2017 09:35:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d6Zdm-0005p1-TX for pgsql-sql@postgresql.org; Fri, 05 May 2017 09:35:10 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d6Zdk-0008W2-2T for pgsql-sql@postgresql.org; Fri, 05 May 2017 09:35:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To:Message-ID:Subject:Cc:To:Sender:From:Date; bh=DLkcYRwIs0FgVVWJeVB19MOCwlTVu6aSR9NfCGPs1Vo=; b=NBhns/QInaANhBHtPbXNILLjjNqvIhU7nhXpDTXNrxEE7jp9odlfubBJbURsH6pYTWUVh0pkcw24bRyf0w9F4C/Cn0ifQ6PRTO3LaZuFV3r02xPiBDsjDSyRSLPdsqWpKdrXPREJkfCFzrYz4BiXclNsw+//jwB9tl79kx5cRF4=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.84_2) (envelope-from ) id 1d6Zdh-0001kO-O1; Fri, 05 May 2017 11:35:05 +0200 Date: Fri, 5 May 2017 11:35:05 +0200 From: hubert depesz lubaczewski To: Gary Stainburn Cc: pgsql-sql@postgresql.org Subject: Re: Most recent row Message-ID: <20170505093505.GA5611@depesz.com> Reply-To: depesz@depesz.com References: <201705050925.04194.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <201705050925.04194.gary.stainburn@ringways.co.uk> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Fri, May 05, 2017 at 09:25:04AM +0100, Gary Stainburn wrote: > This question has been asked a few times, and Google returns a few different > answers, but I am interested people's opinions and suggestions for the *best* > wat to retrieve the most recent row from a table. > > My case is: > > create table people ( > p_id serial primary key, > ...... > ); > > create table assessments ( > p_id int4 not null references people(p_id), > as_timestamp timestamp not null, > ...... > ); > > select p.*, (most recent) a.* > from people p, assessments a > .. > ; How many rows are in people? How many in assessments? Do you really want data on all people? Or just some? Best regards, depesz -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql