pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: mysql code questions
Date: Wed, 12 Aug 2009 20:52:33 +0200
Message-ID: <h5v31e$tqn$1@ger.gmane.org> (raw)
In-Reply-To: <20090812181928.GF7527@cns.vt.edu>
References: <20090812181928.GF7527@cns.vt.edu>

Ray Stell wrote on 12.08.2009 20:19:
> 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? 
That article talks about SQL Server not MySQL.

> 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;

I would probably do it this way:

SELECT tt. *
FROM testtable tt
WHERE create_date = (SELECT MAX(create_date)
                      FROM testtable tt2
                      WHERE tt.id = tt2.id);

Don't know which one is more efficient (with just a few rows, it doesn't really pay off to look at 
the execution plan)

Thomas




view thread (3+ messages)  latest in thread

Message-ID: <h5v31e$tqn$1@ger.gmane.org>
Permalink:  ../h5v31e$tqn$1@ger.gmane.org/
Also on:    postgresql.org/message-id/h5v31e$tqn$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: mysql code questions
  In-Reply-To: <h5v31e$tqn$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox