Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 075BC635423 for ; Wed, 12 Aug 2009 15:24:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 05150-01-9 for ; Wed, 12 Aug 2009 18:24:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from locust.cns.vt.edu (locust.cns.vt.edu [198.82.169.14]) by mail.postgresql.org (Postfix) with ESMTP id C4079635F9B for ; Wed, 12 Aug 2009 15:19:29 -0300 (ADT) Received: by locust.cns.vt.edu (Postfix, from userid 986) id 906C0118E4D; Wed, 12 Aug 2009 14:19:28 -0400 (EDT) Date: Wed, 12 Aug 2009 14:19:28 -0400 From: Ray Stell To: pgsql-sql@postgresql.org Subject: mysql code questions Message-ID: <20090812181928.GF7527@cns.vt.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.31 tagged_above=-10 required=5 tests=AWL=0.430, BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 200908/58 X-Sequence-Number: 32967 http://www.brentozar.com/archive/2009/04/getting-the-most-recent-record/ How this works? What is ttNewer? What is a clustered primary key in mysql? This is as good as I can do to get this into pg: create table TestTable ( id int not null, create_date date not null, info1 VARCHAR(50) NOT NULL, info2 VARCHAR(50) NOT NULL, constraint PK_TestTable PRIMARY KEY(id,create_date) ); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (1, '1/1/09', 'Blue', 'Green'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (1, '1/2/09', 'Red', 'Yellow'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (1, '1/3/09', 'Orange', 'Purple'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (2, '1/1/09', 'Yellow', 'Blue'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (2, '1/5/09', 'Blue', 'Orange'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (3, '1/2/09', 'Green', 'Purple'); INSERT INTO TestTable (id, create_date, info1, info2) VALUES (3, '1/8/09', 'Red', 'Blue'); select tt.* FROM TestTable tt LEFT OUTER JOIN TestTable ttNewer ON tt.id = ttNewer.id AND tt.create_date < ttNewer.create_date WHERE ttNewer.id IS NULL; id | create_date | info1 | info2 ----+-------------+--------+-------- 1 | 2009-01-03 | Orange | Purple 2 | 2009-01-05 | Blue | Orange 3 | 2009-01-08 | Red | Blue (3 rows)