Re: mysql code questions - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: mysql code questions
Date
Msg-id h5v31e$tqn$1@ger.gmane.org
Whole thread Raw
In response to mysql code questions  (Ray Stell <stellr@cns.vt.edu>)
Responses Re: mysql code questions  (Greg Stark <gsstark@mit.edu>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Ray Stell
Date:
Subject: mysql code questions
Next
From: Greg Stark
Date:
Subject: Re: mysql code questions