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