Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Finding last N records by some_id
- Felix Geerinckx
April 27, 2005, 11:06 am
rate this thread
Here is a problem I've encountered a few times lately:
CREATE TABLE foo(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
some_id INT NOT NULL,
ts TIMESTAMP NOT NULL
find the last (ordered by ts) N id's for each some_id, with N > 1.
Is this possible in "pure" (i.e. without application code) MySQL 4.1.x?
Re: Finding last N records by some_id
I don't have time to test it, but something like:
ORDER BY ts DESC
should do it for you. My idea is order them most recent first then limit
the number of rows returned. Hope this helps.
On Wed, 27 Apr 2005 11:06:52 +0000, Felix Geerinckx wrote:
Custom Office solutions
and Windows/UNIX/OSX programs
- » How to backup database data without direct server access
- — Next thread in » MySQL Database Forum
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum