Re: mysql code questions

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: mysql code questions
Date: 2009-08-12 18:52:33
Message-ID: h5v31e$tqn$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Stark 2009-08-12 19:00:38 Re: mysql code questions
Previous Message Ray Stell 2009-08-12 18:19:28 mysql code questions